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 |
CE是什么情况?#include<string.h> #include<stdio.h> using namespace std; const int maxn=1e5+10; char str[15],str1[maxn][11],str2[maxn][11]; struct Trienode { int t=0; Trienode *next2[26]; Trienode() { for(int i=0; i<26; i++) next2[i]=NULL; } }; Trienode *head; void buildTrie(char *s,int n) {int i,index; Trienode *p=head; for( i=0; i<strlen(s); i++) { index=s[i]-'a'; if(!p->next2[index]) { p->next2[index]=new Trienode(); } p=p->next2[index]; } p->t=n; } int searchTrie(char *s) { int index,i; Trienode *p=head; for(i=0; i<strlen(s); i++) { index=s[i]-'a'; if(!p->next2[index]) { return -1; } p=p->next2[index]; } return p->t; } int main() { int i = 0, k ; head = new Trienode(); while(gets(str)&&strlen(str)!=0) { sscanf(str,"%s %s", str1[i], str2[i]); buildTrie(str2[i],i); i++ ; } while(gets(str)&&strlen(str)!=0) { k = searchTrie(str); if(k == -1) printf("eh\n"); else printf("%s\n", str1[k]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator