hdu2094
思路:最后未被击败的选手数是否为1
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 int main() 6 { 7 int i, j, n, score[1001], number; 8 char name[1001][100], a[1000], b[1000]; 9 10 while( scanf( "%d", &n ) ) 11 { 12 if( n == 0 ) 13 break; 14 15 memset( name, 0, sizeof(name) ); 16 memset( score, 0, sizeof(score) ); 17 for( i = 0, number = 0; i < n; i ++ ) 18 { 19 scanf( "%s %s", a, b ); 20 for( j = 0; j < number; j ++ ) 21 { 22 if( strcmp( a, name[j] ) == 0 ) 23 break; 24 } 25 if( j >= number ) 26 { 27 strcpy( name[number], a ); 28 number ++; 29 } 30 for( j = 0; j < number; j ++ ) 31 { 32 if( strcmp( b, name[j] ) == 0 ) 33 { 34 score[j] --; 35 } 36 } 37 if( j >= number ) 38 { 39 strcpy( name[number], b ); 40 score[number] --; 41 number ++; 42 } 43 } 44 for( i = 0, j = 0; i < number; i ++ ) 45 { 46 if( score[i] == 0 ) 47 j ++; 48 } 49 if( j == 1 ) 50 printf( "Yes\n" ); 51 else 52 printf( "No\n" ); 53 } 54 55 return 0; 56 }