PAT乙级 锤子剪刀布 (20)

这是一篇关于PAT乙级考试中的一道水题的解析,主要涉及统计和判断过程,通过对输入数据的分析,进行锤子剪刀布游戏的决策输出。
摘要由CSDN通过智能技术生成

水题

输入并统计,最后在做判断之后输出.

#include "iostream"
#include "string.h"
using namespace std;

int main()
{
	int count;
	
	int win1=0,lost1=0,band1=0;
	int win2=0,lost2=0,band2=0;
	int num1[3],num2[3];
	memset(num1,0,sizeof(num1));
	memset(num2,0,sizeof(num2));
	//1 c 2 j 3 b
	char result1,result2;
	char tempa,tempb;

	cin>>count;
	
	while(count--)
	{
		
		cin>>tempa>>tempb;

		if(tempa == tempb)
		{
			band1++;
			band2++;

		}	
		else if((tempa == 'C'&&tempb == 'J')||(tempa == 'J'&&tempb == 'B')||(tempa == 'B'&&tempb == 'C'))
		{
			if(tempa == 'C')
				num1[0]++;
			else if (tempa == 'J')
				num1[1]++;
			else if (tempa == 'B')
				num1[2]++;
			win1++;
			lost2++;
		}
		else
		{
			if(tempb == 'C')
				num2[0]++;
			else if (tempb == 'J')
				num2[1]++;
			else if (tempb == 'B')
				num2[2]++;
			lost1++;
			win2++;
		}
	}

	cout<<win1<<" "<<band1<<" "<<lost1<<endl;
	cout<<win2<<" "<<band2<<" "<<lost2<<endl;

	if(num1[2]>=num1[0]&&num1[2]>=num1[1])
	{
		cout<<"B";
	}
	else if(num1[0]>=num1[1]&&num1[0]>=num1[2])
	{
		if(num1[0]==num1[2])
			cout<<"B";
		else
			cout<<"C";
	}
	else if(num1[1]>=num1[0]&&num1[1]>=num1[2])
	{
		if(num1[1]==num1[2])
			cout<<"B";
		else if(num1[1]==num1[0])
			cout<<"C";
		else
			cout<<"J";
	}

	cout<<" ";

	if(num2[2]>=num2[0]&&num2[2]>=num2[1])
	{
		cout<<"B";
	}
	else if(num2[0]>=num2[1]&&num2[0]>=num2[2])
	{
		if(num2[0]==num2[2])
			cout<<"B";
		else
			cout<<"C";
	}
	else if(num2[1]>=num2[0]&&num2[1]>=num2[2])
	{
		if(num2[1]==num2[2])
			cout<<"B";
		else if(num2[1]==num2[0])
			cout<<"C";
		else
			cout<<"J";
	}
	cout<<endl;

	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值