Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这或许是最简单的C++ code了,没用任何复杂的数据结构和算法。。int n,m; char p[100002][8],ss[22]; bool ismatch(char pt[],char s[]) { int n1=strlen(pt),n2=strlen(s),i=0,j=0,imatch=-1,prej=-1; while(i<n2) { if(j<n1&&pt[j]=='*') { prej=j++; imatch=i; } else if(j<n1&&(pt[j]==s[i]||pt[j]=='?')) { i++; j++; } else if(imatch!=-1) { i=++imatch; j=prej; } else return false; } while(j<n&&pt[j]=='*') j++; return j==n1; } int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%s",&p[i]); while(m--) { scanf("%s",&ss); int flag=0; for(int i=0;i<n;i++) { if(ismatch(p[i],ss)) { printf("%d ",i); flag=1; } } if(flag) printf("\n"); else printf("Not match\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator