Source
Problem Id:1013 User Id:bearl
Memory:20K Time:0MS
Language:C++ Result:Accepted
#include<iostream.h>
#include<string.h>
struct
{
char l[7];
char r[7];
char e[5];
} w[3];
int myf(char ctf,int wc);
void main()
{
int n,cases,i;
char ctf;
cin>>n;
for(cases=0;cases<n;cases++)
{
for(i=0;i<3;i++)
cin>>w[i].l>>w[i].r>>w[i].e;
for(ctf='A';ctf<='L';ctf++)
{
if(myf(ctf,-1))
{
cout<<ctf<<" is the counterfeit coin and it is light."<<endl;
break;
}
if(myf(ctf,1))
{
cout<<ctf<<" is the counterfeit coin and it is heavy."<<endl;
break;
}
}
}
}
int myf(char ctf,int wc)
{
int wl,wr,i;
for(i=0;i<3;i++)
{
if(strchr(w[i].l,ctf))
wl=wc;
else
wl=0;
if(strchr(w[i].r,ctf))
wr=wc;
else
wr=0;
if((wl>wr) && strcmp(w[i].e,"up") ||
(wl<wr) && strcmp(w[i].e,"down") ||
(wl==wr) && strcmp(w[i].e,"even") )
return 0;
}
return wc;
}