poj 1013(找出假币)

题目链接:http://poj.org/problem?id=1013

转载至:http://blog.csdn.net/lyy289065406/article/details/6661421

 

代码:
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
	int cases;
	cin>>cases;
	for(int c=1;c<=cases;c++){
		char left[3][6],right[3][6],status[3][6];

		int time['L'+1]={0};  //标记各个字母被怀疑的次数
		bool zero['L'+1]={false};  //标记绝对为真币的字母(令天枰平衡的所有字母)

		for(int k=0;k<3;k++)
			cin>>left[k]>>right[k]>>status[k];	

		for(int i=0;i<3;i++){
			switch(status[i][0]){  //检查天枰状态
			case 'u':     //up,天枰左重右轻
				{
					for(int j=0;left[i][j];j++){
						time[ left[i][j] ]++;  //左重
						time[ right[i][j] ]--;  //右轻
					}
					break;
				}
			case 'd':     //down,天枰左轻右重
				{
					for(int j=0;left[i][j];j++){
						time[ left[i][j] ]--;  //左轻
						time[ right[i][j] ]++;  //右重
					}
					break;
				}
			case 'e':     //down,天枰平衡
				{
					for(int j=0;left[i][j];j++){
						zero[ left[i][j] ]=true;   //绝对真币
						zero[ right[i][j] ]=true;   //绝对真币
					}
					break;
				}
			}
		}

		int max=-1;  //查找被怀疑程度最高的硬币(假币)
		char alpha;
		for(int j='A';j<='L';j++){
			if(zero[j])  //绝对真币
				continue;

			if(max<=abs(time[j]))
			{
				max=abs(time[j]);
				alpha=j;
			}
		}
		cout<<alpha<<" is the counterfeit coin and it is ";
		if(time[alpha]>0)
			cout<<"heavy."<<endl;
		else
			cout<<"light."<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值