| ||||||||||
| 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 | |||||||||
寻求大牛的指点 急急#include <iostream>
#include <string>
using namespace std;
char s1[3][6],s2[3][6],s[3][6];
bool seek(int x, int y)
{
int c[12];
int t1,t2;
int i,j;
for(i = 0; i < 12; i++){
c[i]=0;
}
c[x] = y;
for(i = 0; i < 3; i++){
t1=0;
t2=0;
for(j = 0; s1[i][j]!='\0';j++){
t1+=c[s1[i][j]-'A'];
t2+=c[s2[i][j]-'A'];
}
if(s[i][0]=='e')
if(t1 != t2)
return false;
if(s[i][0]=='u')
if(t1 <= t2)
return false;
if(s[i][0]=='d')
if(t1 >= t2)
return false;
}
return true;
}
int main(){
char b[12]={'A','B','C','D','E','F','G','H','I','J','K','L'};
int a[12];
int i,j;
int n;
cin>>n;
while(n--)
{
for(i = 0; i < 12; i++)
{
a[i] = 0;
}
for(j = 0 ;j < 3; j++)
{
cin>>s1[j]>>s2[j]>>s[j];
if(s[j][0]=='e')
continue;
if(s[j][0]=='u'){
i=0;
while(s1[j][i]!='\0')
{
if(a[s1[j][i]-'A'] == -1)
a[s1[j][i]-'A'] = 0;
else
a[s1[j][i]-'A'] = 1;
i++;
}
i=0;
while(s2[j][i] != '\0')
{
if(a[s2[j][i]-'A'] == 1)
a[s2[j][i]-'A'] = 0;
else
a[s2[j][i]-'A'] = -1;
i++;
}
}
else if(s[j][0]=='d')
{
i=0;
while(s1[j][i]!='\0'){
if(a[s1[j][i]-'A'] == 1)
a[s1[j][i]-'A'] = 0;
else
a[s1[j][i]-'A'] = -1;
i++;
}
i=0;
while(s2[j][i]!='\0')
{
if(a[s2[j][i]-'A'] == -1)
a[s2[j][i]-'A'] = 0;
else
a[s2[j][i]-'A'] = 1;
i++;
}
}
}
for(i = 0; i < 12; i++){
if(a[i] == 1 || a[i]==-1){
if( seek( i , a[i] ) )
break;
}
}
cout<<b[i];
printf(" is the counterfeit coin and it is ");
puts(a[i]<0 ? "light.":"heavy.");
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator