#include<iostream>
#include<cstring>
using namespace std;
char Left[3][7],Right[3][7],Result[3][7];
bool isLight(char c)
{
for(int i=0;i<3;i++)
{
if(strcmp(Result[i],"even")==0)
{
if(strchr(Left[i],c)!=NULL||strchr(Right[i],c)!=NULL)
return false;
}
if(strcmp(Result[i],"up")==0)
{
if(strchr(Right[i],c)==NULL)return false;
}
if(strcmp(Result[i],"down")==0)
{
if(strchr(Left[i],c)==NULL)return false;
}
}
return true;
}
bool isHeavy(char c)
{
for(int i=0;i<3;i++)
{
if(strcmp(Result[i],"even")==0)
{
if(strchr(Left[i],c)!=NULL||strchr(Right[i],c)!=NULL)
return false;
}
if(strcmp(Result[i],"up")==0)
{
if(strchr(Left[i],c)==NULL)return false;
}
if(strcmp(Result[i],"down")==0)
{
if(strchr(Right[i],c)==NULL)return false;
}
}
return true;
}
int main()
{
int n;
cin>>n;
while(n--)
{
for(int i=0;i<3;i++)
cin>>Left[i]>>Right[i]>>Result[i];
for (char c = 'A'; c <= 'L'; c++ )
{
if ( isLight(c) )
{
cout<<c<<" is the counterfeit coin and it is light.\n";
break;
}
if ( isHeavy(c) )
{
cout<<c<<" is the counterfeit coin and it is heavy.\n";
break;
}
}
}
return 0;
}
<iostream>
#include<cstring>
using namespace std;
char Left[3][7],Right[3][7],Result[3][7];
bool isLight(char c)
{
for(int i=0;i<3;i++)
{
if(strcmp(Result[i],"even")==0)
{
if(strchr(Left[i],c)!=NULL||strchr(Right[i],c)!=NULL)
return false;
}
if(strcmp(Result[i],"up")==0)
{
if(strchr(Right[i],c)==NULL)return false;
}
if(strcmp(Result[i],"down")==0)
{
if(strchr(Left[i],c)==NULL)return false;
}
}
return true;
}
bool isHeavy(char c)
{
for(int i=0;i<3;i++)
{
if(strcmp(Result[i],"even")==0)
{
if(strchr(Left[i],c)!=NULL||strchr(Right[i],c)!=NULL)
return false;
}
if(strcmp(Result[i],"up")==0)
{
if(strchr(Left[i],c)==NULL)return false;
}
if(strcmp(Result[i],"down")==0)
{
if(strchr(Right[i],c)==NULL)return false;
}
}
return true;
}
int main()
{
int n;
cin>>n;
while(n--)
{
for(int i=0;i<3;i++)
cin>>Left[i]>>Right[i]>>Result[i];
for (char c = 'A'; c <= 'L'; c++ )
{
if ( isLight(c) )
{
cout<<c<<" is the counterfeit coin and it is light.\n";
break;
}
if ( isHeavy(c) )
{
cout<<c<<" is the counterfeit coin and it is heavy.\n";
break;
}
}
}
return 0;
}
北大OJ1013
最新推荐文章于 2022-01-01 11:07:41 发布