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 |
众位兄弟姐妹帮看看吧,我都快没语言了,save me!!!#include <iostream> using std::cout; using std::cin; using std::endl; int judge( char ); int weigh( char ); char left[3][7], right[3][7], bal[3][5]; int main() { int times; char result[500][2]; cin >> times; for ( int k = 0; k < times; k++ ) { for ( int i = 0; i < 3; i++ ) cin >> left[i] >> right[i] >> bal[i]; char coin; for ( coin = 'A'; coin <= 'L'; coin++ ) { int bad = judge( coin ); if ( bad == 1 ) break; } result[k][0] = coin; int weight = weigh( coin ); result[k][1] = weight; } for ( k =0; k < times; k++ ) { if ( result[k][1] == 2 ) cout << result[k][0] << " is the counterfeit coin and it is heavy." << endl; else cout << result[k][0] << " is the counterfeit coin and it is light." << endl; } return 0; } int judge( char c ) { int x = 1; for ( int i = 0; i < 3; i++ ) { for ( int j = 0; j < strlen( left[i] ); j++ ) { if ( ( c == left[i][j] || c == right[i][j] ) && bal[i][0] == 'e' ) { x = 0; break; } else { if ( c != left[i][j] && c != right[i][j] && bal[i][0] != 'e' ) { x = 0; break; } } } } return x; } int weigh( char c ) { int y = 2; for ( int i = 0; i < 3; i++ ) { if ( bal[i][0] == 'u' ) { for ( int j = 0; j < strlen( left[i] ); j++ ) { if ( c == left[i][j] ) y = 2; if ( c == right[i][j] ) y = 1; else break; } } if ( bal[i][0] == 'd' ) { for ( int j = 0; j < strlen( left[i] ); j++ ) { if ( c == left[i][j] ) y = 1; if ( c == right[i][j] ) y = 2; else break; } } else break; } return y; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator