#include <iostream>
using namespace std;
int find( char* a, char* b, char c, char* d )
{
if ( strcmp(d, "even" )== 0 )
{
for ( int i= 0; i< strlen(a); ++i )
if ( a[i]== c )
return 0;
for ( int i= 0; i< strlen(b); ++i )
if ( b[i]== c )
return 0;
}
else if ( strcmp(d, "down" )== 0 )
{
for ( int i= 0; i< strlen(a); ++i )
if ( a[i]== c )
return 1;
for ( int i= 0; i< strlen(b); ++i )
if ( b[i]== c )
return 2;
}
else if ( strcmp(d,"up")== 0 )
{
for ( int i= 0; i< strlen(a); ++i )
if ( a[i]== c )
return 2;
for ( int i= 0; i< strlen(b); ++i )
if ( b[i]== c )
return 1;
}
return -1;
}
int main()
{
int n;
scanf("%d",&n);
char a[3][15];
char b[3][15];
char j[3][8];
bool vi[15];
while( n-- )
{
memset( vi, false, sizeof(vi) );
for ( int i= 0; i< 3; ++i )
scanf("%s%s%s", a[i], b[i], j[i] );
for ( int i= 0; i< 3; ++i )
{
for ( int j= 0; j< strlen(a[i]); ++j )
vi[ a[i][j]- 'A' ]= true;
for ( int j= 0; j< strlen(b[i]); ++j )
vi[ b[i][j]- 'A' ]= true;
}
int num= -1;
int s= 0;
int id= -1;
for ( int i= 0; i< 15; ++i )
if ( vi[i] )
{
int style= -1;
bool isok= true;
int n= 0;
for ( int t= 0; t< 3; ++t )
{
int m= find( a[t], b[t], i+ 'A', j[t] );
if ( m== 1 )
{
if ( style== -1 ) style= m;
else if ( style!= m ) isok= false;
n++;
}
else if ( m== 2 )
{
if ( style== -1 ) style= m;
else if ( style!= m ) isok= false;
n++;
}
else if ( m== 0 )
{
if ( style== -1 ) style= m;
else if ( style!= m ) isok= false;
n++;
}
}
if ( isok && style!= 0 && n> num )
{
num= n;
s= style;
id= i;
}
}
if ( s== 1 )
printf("%c is the counterfeit coin and it is light.\n", id+ 'A' );
else if ( s== 2 )
printf("%c is the counterfeit coin and it is heavy.\n", id+ 'A' );
}
return 0;
}
posted on 2008-10-01 14:32
Darren 阅读(148)
评论(0) 编辑 收藏 引用