您的位置:首页 > 其它

【HDOJ】2585 Hotel

2014-12-23 10:01 183 查看
字符串水题。

#include <cstdio>
#include <cstring>
#include <cstdlib>

#define MAXN 55
char src[MAXN];
char des[MAXN];

bool check(char *s, char *d) {
if (*s=='\0' && *d=='\0')
return true;
if (*s=='*' && *(s+1)=='\0')
return true;
if (*s == *d)
return check(s+1, d+1);
else if (*s=='?' && *d)
return check(s+1, d+1);
else if (*s == '*') {
while (*d) {
if (check(s+1, d))    // match more than 1 char
return true;
++d;
}
}

return false;
}

int main() {
int n;
int ans;

#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif

while (scanf("%s", src) != EOF) {
scanf("%d", &n);
ans = 0;
while (n--) {
scanf("%s", des);
if (check(src, des))
++ans;
}
printf("%d\n", ans);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: