【B1018/模拟】锤子剪刀布(巧用数组)

#include<iostream>
using namespace std;
char mp[3] = { 'B','C','J' };
int change(char c) {
	if (c == 'B') return 0;
	if (c == 'C') return 1;
	if (c == 'J') return 2;
}
int main() {
	char x1, x2;
	int n;
	int m1, m2;
	cin >> n;
	int times_A[3] = { 0 }, times_B[3] = { 0 };
	int hand_A[3] = { 0 }, hand_B[3] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> x1 >> x2;
		m1 = change(x1);
		m2 = change(x2);
		if ((m1 + 1) % 3 == m2) {
			times_A[0]++;
			times_B[2]++;
			hand_A[m1]++;
		}
		else if (m1 == m2) {
			times_A[1]++;
			times_B[1]++;
		}
		else {
			times_B[0]++;
			times_A[2]++;
			hand_B[m2]++;
		}
	}
	for (int i = 0; i < 3; i++) cout << times_A[i] << " ";
	cout << endl;
	for (int i = 0; i < 3; i++) cout << times_B[i] << " ";
	cout << endl;
	int n1, n2;
	int temp1 = -1,temp2=-1;
	for (int i = 0; i < 3; i++) {
		if (hand_A[i] > temp1) {
			temp1 = hand_A[i];
			n1 = i;
		}
	}
	for (int i = 0; i < 3; i++) {
		if (hand_B[i] > temp2) {
			temp2 = hand_B[i];
			n2 = i;
		}
	}
	cout << mp[n1] << " " << mp[n2];
	system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值