标签:des style blog http color io os java ar
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10720 Accepted Submission(s): 3701
字符串排序再扫描一遍即可
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cmath> 5 #include<stdlib.h> 6 #include<algorithm> 7 using namespace std; 8 const int MAXN=10000+5; 9 int T,n; 10 struct node 11 { 12 char str[10+5]; 13 }a[MAXN]; 14 15 int cmp(const node A,const node B) 16 { 17 return strcmp(A.str,B.str)<0; 18 } 19 20 int judge(char a[],char b[]) 21 { 22 int len=strlen(a); 23 for(int i=0;i<len;i++) 24 if(a[i]!=b[i]) 25 return 0; 26 return 1; 27 } 28 int main() 29 { 30 //freopen("in.txt","r",stdin); 31 scanf("%d",&T); 32 while(T--) 33 { 34 scanf("%d",&n); 35 for(int i=0;i<n;i++) 36 scanf("%s",a[i].str); 37 38 sort(a,a+n,cmp);//利用结构体对字符串排序 39 40 int ok=0; 41 for(int i=0;i<n-1;i++) 42 { 43 if(judge(a[i].str,a[i+1].str)) 44 { 45 ok=1; 46 break; 47 } 48 } 49 50 if(ok) 51 printf("NO\n"); 52 else 53 printf("YES\n"); 54 } 55 return 0; 56 }
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/clliff/p/3965269.html