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 |
Re:终于过了,谢谢In Reply To:Re:终于过了,谢谢 Posted by:shitfuck at 2005-03-12 13:43:58 这是我的程序,哪位高手帮忙看看哪里错了 我是按照这个思路写的: 某次称量结果为even,所有出现硬币为真; 某次称量结果为up,左边的不轻,右边的不重,不在上面的都为真; 某次称量结果为down,左边的不重,右边的不轻,不在上面的都为真; #include <iostream.h> #include <string.h> void main(){ int nState[12][3]; for (int i = 0; i < 12; i ++){ for (int j = 0 ; j < 3; j ++) nState[i][j] = 0 ; } int nCases; cin >> nCases; for (i = 0 ; i < nCases ; i ++){ char szCase [3][3][15]; for (int j = 0 ; j < 3 ; j ++){ for (int k = 0 ; k < 3 ; k ++) cin >> szCase[j][k]; } for (j = 0; j < 3 ; j ++){ if (!strcmp(szCase [j][2],"even")){ for (int k = 0; k < strlen(szCase [j][0]) ; k++){ nState[szCase[j][0][k] - 'A'][2] = 1; nState[szCase[j][1][k] - 'A'][2] = 1; } } if (!strcmp(szCase [j][2],"up")){ int appeared = 0; for (int l = 0 ; l < 12 ; l ++){ //找出未出现的并标记为真 for (int k = 0; k < strlen(szCase [j][0]); k++){ if (l == szCase [j][0][k] - 'A'){ appeared = 1; break; } } for (k = 0; k < strlen(szCase [j][1]); k++){ if (l == szCase [j][1][k] - 'A'){ appeared = 1; break; } } if (appeared == 0) nState[l][2] = 1; } for (int k = 0; k < strlen(szCase [j][0]); k++){ nState[szCase[j][0][k] - 'A'][0] = 1; nState[szCase[j][1][k] - 'A'][1] = 1; } } if (!strcmp(szCase [j][2],"down")){ int appeared = 0; for (int l = 0 ; l < 12 ; l ++){ //找出未出现的并标记为真 for (int k = 0; k < strlen(szCase [j][0]); k++){ if (l == szCase [j][0][k] - 'A'){ appeared = 1; break; } } for (k = 0; k < strlen(szCase [j][1]); k++){ if (l == szCase [j][1][k] - 'A'){ appeared = 1; break; } } if (appeared == 0) nState[l][2] = 1; } for (int k = 0; k < strlen(szCase [j][0]); k++){ nState[szCase[j][0][k] - 'A'][1] = 1; nState[szCase[j][1][k] - 'A'][0] = 1; } } } for (j = 0; j < 12; j ++){ if (nState[j][2] != 1){ if (nState[j][0] == 1 && nState[j][1] != 1) cout << char(j + 'A') << " is the counterfeit coin and it is heavy."<<endl; if (nState[j][0] != 1 && nState[j][1] == 1) cout << char(j + 'A') << " is the counterfeit coin and it is light."<<endl; } } } } 谢谢 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator