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

枚举每一个coin,如果不是false即为true,一定看得懂

Posted by unshakable at 2017-03-28 22:10:46 on Problem 1013
#include <iostream>
#include <cstring>
using namespace std;

char Left[3][7];
char Right[3][7];
char Result[3][5];

//true == light false == heavy
bool isCounterfeit(char c, bool weight)
{
	for (int i = 0; i < 3; i++)
		switch (Result[i][0]) {
			case 'e':
				if (strchr(Left[i], c) || strchr(Right[i], c)) return false; break;
			case 'u': //the right side is light
				if (weight) { //light coin
					if (strchr(Right[i], c) == NULL) return false; //in the right side of the balance
				}
				else {		  //heavy coin
					if (strchr(Left[i], c) == NULL) return false;  //in the left side of the balance
				}
				break;
			case 'd': //the right side is heavy
				if (weight) { //light coin
					if (strchr(Left[i], c) == NULL) return false; //in the left side of the balance
				}
				else {		  //heavy coin
					if (strchr(Right[i], c) == NULL) return false; //in the right side of the balance
				}
				break;
	}
	return true;
}

int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < 3; i++)
			cin >> Left[i] >> Right[i] >> Result[i];
		for (char c = 'A'; c <= 'L'; c++) {
			if (isCounterfeit(c, true)) {
				cout << c << " is the counterfeit coin and it is light." << endl;
				break;
			}
			if (isCounterfeit(c, false)) {
				cout << c << " is the counterfeit coin and it is heavy." << endl;
				break;
			}
		}
	}

	return 0;
}

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