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:这题有个思路比较清晰的方法 Posted by:smallrain at 2005-11-17 18:07:24 思路基本一样为什么总是wa #include<iostream> #include<cmath> using namespace std; void main() { const int NumOfDollar = 12; int num; char left[3][7] = {'\0'}, right[3][7] = {'\0'}, result[3][5] = {'\0'}; static int dollar[NumOfDollar]; const int REAL = 100; int i, k, j; char c; cin>>num; for(k = 0; k < num; k++){ for(j = 0; j < 3; j++) cin>>left[j]>>right[j]>>result[j]; for(i = 0; i < 3; i++){ c = result[i][0]; switch(c){ case 'u': for(j = 0; left[i][j]; j++){ if(dollar[left[i][j] - 'A'] != REAL) dollar[left[i][j] - 'A']++; if(dollar[right[i][j] - 'A'] != REAL) dollar[right[i][j] - 'A']--; } break; case 'd': for(j = 0; left[i][j]; j++){ if(dollar[left[i][j] - 'A'] != REAL) dollar[left[i][j] - 'A']--; if(dollar[right[i][j] - 'A'] != REAL) dollar[right[i][j] - 'A']++; } break; case 'e': for(j = 0; left[i][j]; j++){ dollar[left[i][j] - 'A'] = REAL; dollar[right[i][j] - 'A'] = REAL; } break; } } int index; for(i = 0; dollar[i] == REAL; i++); index = i; for(; i < NumOfDollar; i++){ if(dollar[i] != REAL){ if(abs(dollar[i]) > abs(dollar[index])) index = i; } } if(dollar[index] > 0) cout<<(char)('A' + index)<<" is the counterfeit coin and it is heavy."<<endl; else cout<<(char)('A' + index)<<" 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