uva 475 - Wild Thing(字符串处理)
2014-09-02 19:41
232 查看
题目链接:uva 475 - Wild Thing
题目大意:给定一个字符串的通配,然后给定一些字符集,问说有哪些字符满足匹配,如果没有一个字符串匹配的话,当前这组数据就任何东西也不输出,包括换行。
解题思路:递归去匹配即可,注意∗,∗∗∗这种数据。
题目大意:给定一个字符串的通配,然后给定一些字符集,问说有哪些字符满足匹配,如果没有一个字符串匹配的话,当前这组数据就任何东西也不输出,包括换行。
解题思路:递归去匹配即可,注意∗,∗∗∗这种数据。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 50; int n, m; char s[maxn], t[maxn]; bool dfs (int l, int r) { if (l > n && r > m) return true; if (l > n || r > m) return false; if (s[l] == '*') { while (s[l+1] == '*') l++; if (s[l+1] == t[r] && dfs(l + 1, r)) return true; return dfs(l, r + 1); } else { if (s[l] != t[r]) return false; return dfs(l + 1, r + 1); } return false; } bool judge () { n = strlen(s); m = strlen(t); return dfs(0, 0); } int main () { int cas = 0; while (gets(s)) { int ret = 0; while (gets(t) && t[0] != '\0') { if (judge()) { if (ret++ == 0) { if (cas) printf("\n"); printf("MATCHES FOR THE PATTERN: %s\n", s); } printf("%s\n", t); } } if (ret) cas++; } return 0; }
相关文章推荐
- uva 10878 Decode the tape(字符串处理)
- uva 10815 Andy's First Dictionary(字符串处理+sort排序)
- UVa 455 Periodic Strings (字符串处理)
- [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
- uva:310 - L--system(字符串处理+ bfs)
- uva 401 Palindromes(字符串处理)
- Immediate Decodability - UVa 644 字符串处理
- UVa 494 Kindergarten Counting Game (字符串处理)
- UVa 10340 All in All (字符串处理&编程技巧)
- Automatic Poetry - UVa 10361 简单字符串处理
- uva 644 Immediate Decodability(字符串处理)
- uva 502 DEL command(字符串处理)
- uva 185 Roman Numerals (深搜+字符串处理)
- uva 11988 Broken Keyboard(字符串处理+ STL)
- uva 401 Palindromes(基本的字符串处理)
- UVA 156 Ananagrams 模拟+字符串处理
- uva 409 Excuses, Excuses!(字符串处理)
- uva 310 L--system(隐式图搜索+字符串处理)
- (字符串的处理4.7.14)UVA 10252 Common Permutation(寻找两个字符串中的共同字符&&按字典序输出)
- Artificial Intelligence? - UVa 537 字符串处理