hdu2094

产生冠军的条件:(1)获胜的人没输过一次(2)最终获胜的人只有一个

ContractedBlock.gif ExpandedBlockStart.gif View Code
 
     
#include " iostream "
// #include"algorithm"
using namespace std;
#define M 1010
int main()
{
int n;
int i,j;
char a[M][ 100 ],b[M][ 100 ];
int sum[M],c[M];
while (cin >> n,n)
{
memset(sum,
0 , sizeof (sum)); // 0表示失败

for (i = 0 ;i < n;i ++ )
{
cin
>> a[i] >> b[i];
sum[i]
= 1 ; // 1表示获胜

}

for (i = 0 ;i < n;i ++ )
{
for (j = 0 ;j < n;j ++ )
{
if (strcmp(a[i],b[j]) == 0 ) { sum[i] = 0 ;}
}
}

int k = 0 ;
for (i = 0 ;i < n;i ++ )
{
if (sum[i] == 1 ) c[k ++ ] = i;
}
// sort(c,c+k);
int flag = 0 ;
for (i = 1 ;i < k;i ++ )
{
if (strcmp(a[c[i]],a[c[i - 1 ]]) == 0 ) flag ++ ;
}

if (flag == k - 1 ) cout << " Yes " << endl;
else cout << " No " << endl;
}
return 0 ;
}

转载于:https://www.cnblogs.com/FCWORLD/archive/2011/04/07/2007468.html

你可能感兴趣的:(hdu2094)