| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
code (参考)#include <iostream>
#define sMAX 10
#define wordMAX 12
typedef char STRING[sMAX];
typedef bool SET[wordMAX+1];
using namespace std;
SET set1,set2;
int del1(STRING s)
{
int l=strlen(s);
for(int i=0;i<l;i++)
set1[int(s[i]-'A')]=true;
return 0;
}
int del2(STRING s)
{
int l=strlen(s);
for(int i=0;i<l;i++)
set2[int(s[i]-'A')]=true;
return 0;
}
bool in(STRING s,int i)
{
int l=strlen(s);
for(int j=0;j<l;j++)
if(i==int(s[j]-'A')) return true;
return false;
}
int add1(STRING s)
{
for(int i=0;i<12;i++)
if(!in(s,i)) set1[i]=true;
return 0;
}
int add2(STRING s)
{
for(int i=0;i<12;i++)
if(!in(s,i)) set2[i]=true;
return 0;
}
int main()
{
// freopen("A.in","r",stdin);
STRING st1,st2,st3;
int n,j;
cin>>n;
for(int i=0;i<n;i++)
{
memset(set1,false,sizeof(set1));
memset(set2,false,sizeof(set2));
for(j=0;j<3;j++)
{
cin>>st1>>st2>>st3;
if(!strcmp("even",st3))
{
del1(st1);
del1(st2);
del2(st1);
del2(st2);
}
if(!strcmp("up",st3))
{
del1(st1);
add1(st2);
del2(st2);
add2(st1);
}
if(!strcmp("down",st3))
{
del1(st2);
add1(st1);
del2(st1);
add2(st2);
}
}
int temp1=-1,temp2=-1;
for(j=0;j<12;j++)
{
if(!set1[j])
{
if(temp1==-1) temp1=j;
else temp1=-1;
}
if(!set2[j])
{
if(temp2==-1) temp2=j;
else temp2=-1;
}
}
if(temp1==-1) cout<<(char)(temp2+'A')<<" is the counterfeit coin and it is heavy."<<endl;
else cout<<(char)(temp1+'A')<<" is the counterfeit coin and it is light."<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator