标签:
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<set> 5 6 using namespace std; 7 8 const int maxn=100000+10; 9 10 int inde[maxn]; 11 char str1[100]; 12 char str2[100]; 13 set<int>s; 14 15 unsigned int bkdrHash(char *s) 16 { 17 unsigned int seed=131; 18 unsigned int hash=0; 19 while(*s) 20 { 21 hash=hash*seed+(*s++); 22 } 23 24 return (hash%maxn); 25 } 26 27 int main() 28 { 29 int n; 30 while(scanf("%d",&n)) 31 { 32 if(!n) 33 break; 34 35 memset(inde,0,sizeof(inde)); 36 s.clear(); 37 38 for(int i=0;i<n;i++) 39 { 40 scanf("%s",&str1); 41 scanf("%s",&str2); 42 int temp1=bkdrHash(str1); 43 int temp2=bkdrHash(str2); 44 s.insert(temp1); 45 s.insert(temp2); 46 inde[temp2]++; 47 } 48 49 int ans=0; 50 51 set<int>::iterator it; 52 53 for( it=s.begin();it!=s.end();it++) 54 { 55 if(inde[(*it)]==0) 56 ans++; 57 } 58 59 //printf("%d\n",ans); 60 61 if(ans==1) 62 printf("Yes\n"); 63 else 64 printf("No\n"); 65 } 66 67 return 0; 68 }
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4493305.html