Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:这题有个思路比较清晰的方法

Posted by cpp060300548268 at 2006-03-03 12:59:49 on Problem 1013
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator