POJ1013 Counterfeit Dollar

枚举,很普通的题目
Memory: 144K Time: 0MS
Language: C++ Result: Accepted

#include <iostream>
using namespace std;
 
#define false 0
#define true 1
char left_Bal[3][7], right_Bal[3][7], result[3][7];
bool isLight(char x);
bool isHeavy(char x);
 
int main()
{
	int nCases;
	char c;
	scanf("%d", &nCases);
	while(nCases--)
	{
		for(int i = 0; i < 3; i++)
			scanf("%s %s %s", left_Bal[i], right_Bal[i], result[i]);
		for(c = 'A'; c <= 'L'; c++)
		{
			if(isLight(c))
			{
				printf("%c is the counterfeit coin and it is light.\n", c);
				break;
			}
			if(isHeavy(c))
			{
				printf("%c is the counterfeit coin and it is heavy.\n", c);
				break;
			}
		}
	}
	return 0;
}
 
bool isLight(char x)
{
	int i;
	for(i = 0; i < 3; i++)
		switch(result[i][0])
		{
			case 'u':
				if(strchr(right_Bal[i], x) == NULL)
					return false;
				break;
			case 'e':
				if(strchr(right_Bal[i], x) != NULL || strchr(left_Bal[i], x) != NULL)
					return false;
				break;
			case 'd':
				if(strchr(left_Bal[i], x) == NULL)
					return false;
				break;
		}
	return true;
}
 
bool isHeavy(char x)
{
	int i;
	for(i = 0; i < 3; i++)
		switch(result[i][0])
		{
			case 'd':
				if(strchr(right_Bal[i], x) == NULL)
						 return false;
				break;
			case 'e':
				if(strchr(right_Bal[i], x) != NULL || strchr(left_Bal[i], x) != NULL)
					return false;
				break;
			case 'u':
				if(strchr(left_Bal[i], x) == NULL)
						 return false;
				break;
		}
	return true;
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

发表评论

电子邮件地址不会被公开。 必填项已用*标注