标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1511 Accepted Submission(s):
748
1 /******************************* 2 3 Date : 2015-12-09 22:15:29 4 Author : WQJ (1225234825@qq.com) 5 Link : http://www.cnblogs.com/a1225234/ 6 Name : 7 8 ********************************/ 9 #include <iostream> 10 #include <cstdio> 11 #include <algorithm> 12 #include <cmath> 13 #include <cstring> 14 #include <string> 15 #include <set> 16 #include <vector> 17 #include <queue> 18 #include <stack> 19 #define LL long long 20 using namespace std; 21 struct node 22 { 23 node* next[26]; 24 node() 25 { 26 for(int i=0;i<26;i++) 27 next[i]=NULL; 28 } 29 }; 30 int n; 31 char a[110]; 32 int ans; 33 node* root; 34 void insert(char* s,int len) 35 { 36 int i,j; 37 node* p=root; 38 for(i=0;i<len;i++) 39 { 40 int pos=s[i]-‘a‘; 41 if(p->next[pos]==NULL) 42 { 43 ans++; 44 p->next[pos]=new node; 45 p=p->next[pos]; 46 } 47 else 48 p=p->next[pos]; 49 } 50 return; 51 } 52 int main() 53 { 54 freopen("in.txt","r",stdin); 55 while(scanf("%d",&n)!=EOF) 56 { 57 int i,j; 58 int Max=0; 59 ans=0; 60 root=new node; 61 for(i=0;i<n;i++) 62 { 63 scanf("%s",a); 64 int len=strlen(a); 65 Max=max(Max,len); 66 insert(a,len); 67 } 68 printf("%d\n",ans*2+n-Max); 69 } 70 return 0; 71 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5034559.html