| ||||||||||
| 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 | |||||||||
我用的方法是一24种可能一个个试,自己测试都没有问题,但总是WA,那位好心人帮忙看看#include <iostream>
#include <string>
//#include <fstream>
using namespace std;
string str[7];
string result[4];
bool check( int num );
bool in( string &s, char ch );
int main( void )
{
// ifstream ifile( "data.txt" );
int case_num, i;
cin >> case_num;
while( case_num-- )
{
cin >> str[1] >> str[2] >> result[1] >> str[3] >> str[4] >> result[2] >> str[5] >> str[6] >> result[3];
for( i = 1; i <= 24; ++i )
{
if( check( i ) ) // 奇数表示轻
{
cout << ( char )( i / 2 + 'A' ) << " is the counterfeit coin and it is "
<< ( i % 2 == 1 ? "light." : "heavy." ) << endl;
break;
}
}
}
return 0;
}
bool check( int num )
{
char ch;
int i;
int propoty;
ch = ( char )( num / 2 + 'A' );
propoty = num % 2;
for( i = 1; i <= 3; ++i )
{
if( result[i] == "even" )
{
if( in( str[2*i-1], ch ) || in( str[2*i], ch ) ) // 只要这个字母出现在even的地方,则错误
return false;
}
if( result[i] == "up" )
{
if( !in( str[2*i-1], ch ) && !in( str[2*i], ch ) ) // 只要这个字母不出现在不等的地方,则错误
return false;
if( in( str[2*i-1], ch ) && propoty == 1 )
return false;
if( in( str[2*i], ch ) && propoty == 0 )
return false;
}
if( result[i] == "down" )
{
if( !in( str[2*i-1], ch ) && !in( str[2*i], ch ) ) // 只要这个字母不出现在不等的地方,则错误
return false;
if( in( str[2*i-1], ch ) && propoty == 0 )
return false;
if( in( str[2*i], ch ) && propoty == 1 )
return false;
}
}
return true;
}
bool in( string &s, char ch )
{
int i;
for( i = 0; i < s.size(); ++i )
if( ch == s[i] )
return true;
return false;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator