【HDOJ】2585 Hotel

字符串水题。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 
 5 #define MAXN 55
 6 char src[MAXN];
 7 char des[MAXN];
 8 
 9 bool check(char *s, char *d) {
10     if (*s=='' && *d=='')
11         return true;
12     if (*s=='*' && *(s+1)=='')
13         return true;
14     if (*s == *d)
15         return check(s+1, d+1);
16     else if (*s=='?' && *d)
17         return check(s+1, d+1);
18     else if (*s == '*') {
19         while (*d) {
20             if (check(s+1, d))    // match more than 1 char
21                 return true;
22             ++d;
23         }
24     }
25     
26     return false;
27 }
28 
29 int main() {
30     int n;
31     int ans;
32     
33 #ifndef ONLINE_JUDGE
34     freopen("data.in", "r", stdin);
35 #endif
36 
37     while (scanf("%s", src) != EOF) {
38         scanf("%d", &n);
39         ans = 0;
40         while (n--) {
41             scanf("%s", des);
42             if (check(src, des))
43                 ++ans;
44         }
45         printf("%d
", ans);
46     }
47     
48     return 0;
49 }
原文地址:https://www.cnblogs.com/bombe1013/p/4179519.html