标签:match one 重复 not tchar har search single def
Description
Input
Output
Sample Input
5 4 t* ?h*s ??e* *s ?*e this the an is
Sample Output
0 1 3 0 2 4 Not match 3
Source
#include <iostream> #include <cstdio> #include <cstring> #define MAX 600005 using namespace std; int trie[MAX][28]; bool flag[MAX]; int to[100000]; int pos,n,m; bool ans[MAX]; int Insert(char *s) { int i = 0,c = 0; while(s[i]) { int d = isalpha(s[i]) ? s[i] - ‘a‘ : s[i] == ‘?‘ ? 26 : 27; if(!trie[c][d]) trie[c][d] = ++ pos; c = trie[c][d]; i ++; } flag[c] = true; return c; } void check(char *s,int si,int c) { if(si == strlen(s) && flag[c]) { ans[c] = true; } int d = s[si] - ‘a‘; if(trie[c][d]) { check(s,si + 1,trie[c][d]); } if(trie[c][26]) { check(s,si + 1,trie[c][26]); } if(trie[c][27]) { int sj = si; while(sj <= strlen(s)) { check(s,sj,trie[c][27]); sj ++; } } } int main() { char s[30]; scanf("%d%d",&n,&m); for(int i = 0;i < n;i ++) { scanf("%s",s); to[i] = Insert(s); } for(int i = 0;i < m;i ++) { scanf("%s",s); memset(ans,false,sizeof(ans)); int match = 0; check(s,0,0); for(int j = 0;j < n;j ++) { if(ans[to[j]]) { printf("%d ",j); match ++; } } if(!match)printf("Not match"); putchar(‘\n‘); } }
标签:match one 重复 not tchar har search single def
原文地址:https://www.cnblogs.com/8023spz/p/9621040.html