这道又是submission error ,先存下档。
1 #include<cstdio> 2 #include<cstring> 3 const int maxnode=4000*1000+10; 4 int ch[maxnode][62]; 5 int val[62]; 6 int sz; 7 int index(char ch) 8 { 9 if(ch>='0'&&ch<='9') 10 return ch-'0'; 11 else if(ch>'A'&&ch<='Z') 12 return ch-'A'+10; 13 else 14 return ch-'a'+36; 15 } 16 void insert(char *s) 17 { 18 int u=0,len=strlen(s); 19 for(int i=0;i<len;i++) 20 { 21 int c=index(s[i]); 22 if(!ch[u][c]) 23 { 24 memset(ch[sz],0,sizeof(ch[sz])); 25 ch[u][c]=sz++; 26 } 27 u=ch[u][c]; 28 val[u]++; 29 } 30 } 31 int main() 32 { 33 int n; 34 int kcase=1; 35 while(scanf("%d",&n)&&n) 36 { 37 memset(ch[0],0,sizeof(ch[0])); 38 memset(val,0,sizeof(val)); 39 sz=1; 40 char s[1010]; 41 for(int i=0;i<n;i++) 42 { 43 scanf("%s",s); 44 insert(s); 45 } 46 int ans=0; 47 for(int i=1;i<sz;i++) 48 if(val[i]>1) ans+=val[i]; 49 ans+=((n-1)*n)/2; 50 printf("Case %d: %d ",kcase++,ans); 51 } 52 return 0; 53 }