| ||||||||||
| 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:cpp0600548268 at 2006-02-28 11:43:32 > 我用的也是这个思路 为什么不对呢?
> #include<iostream>
> #include<cmath>
> using namespace std;
>
> const int NumOfDollar = 12;
>
> void main()
> {
> int num;
> char left[3][7] = {'\0'}, right[3][7] = {'\0'}, result[3][5] = {'\0'};
> static int dollar[NumOfDollar], rdollar[NumOfDollar];
> 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] != '\0'; j++){
> dollar[left[i][j] - 'A']++;
> dollar[right[i][j] - 'A']--;
> }
> break;
> case 'd': for(j = 0; left[i][j] != '\0'; j++){
> dollar[left[i][j] - 'A']--;
> dollar[right[i][j] - 'A']++;
> }
> break;
> case 'e': for(j = 0; left[i][j] != '\0'; j++){
> rdollar[left[i][j] - 'A'] = 1;
> rdollar[right[i][j] - 'A'] = 1;
> }
> break;
> }
> }
>
> int index;
> for(i = 0; rdollar[i] == 1; i++); index = i;
> for(; i < NumOfDollar; i++){
> if(rdollar[i] == 0){
> 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