1018 锤子剪刀布

大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如大家所知晓:

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。

输入格式:
输入第 1 行给出正整数 N(≤10?5??),即双方交锋的次数。随后 N 行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C 代表“锤子”、J 代表“剪刀”、B 代表“布”,第 1 个字母代表甲方,第 2 个代表乙方,中间有 1 个空格。

输出格式:
输出第 1、2 行分别给出甲、乙的胜、平、负次数,数字间以 1 个空格分隔。第 3 行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有 1 个空格。如果解不唯一,则输出按字母序最小的解。
输入样例:

10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J

输出样例:

5 3 2
2 3 5
B B
  题目分析:一道在天梯赛模拟题中出现的题,按照题目要求对胜、平、负进行计数,最后进行输出即可.
#include<iostream>

using namespace std;

char maxnum(int a, int b, int d) {
	int result = a;
	char c = ‘B‘;
	if (b > result) {
		result = b;
		c = ‘C‘;
	}
	if (result < d) {
		result = d;
		c = ‘J‘;
	}
	return c;
}

int main() {
	int n;
	int as = 0, ap = 0, af = 0, bs = 0, bp = 0, bf = 0;
	int aJ = 0, aC = 0, aB = 0, bJ = 0, bC = 0, bB = 0;
	char a, b;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if ((a == ‘C‘&&b == ‘C‘) || (a == ‘B‘&&b == ‘B‘) || (a == ‘J‘&&b == ‘J‘)) {
			ap++;
			bp++;
		}
		if ((a == ‘C‘ && b == ‘J‘) || (a == ‘J‘ && b == ‘B‘) || (a == ‘B‘ && b == ‘C‘)) {
			as++;
			if (a == ‘C‘)
				aC++;
			if (a == ‘B‘)
				aB++;
			if (a == ‘J‘)
				aJ++;
			bf++;
		}
		if ((b == ‘C‘ && a == ‘J‘) || (b == ‘J‘ && a == ‘B‘) || (b == ‘B‘ && a == ‘C‘)) {
			bs++;
			if (b == ‘C‘)
				bC++;
			if (b == ‘B‘)
				bB++;
			if (b == ‘J‘)
				bJ++;
			af++;
		}
	}
	cout << as << " " << ap << " " << af << endl;
	cout << bs << " " << bp << " " << bf << endl;
	cout << maxnum(aB, aC, aJ) << " " << maxnum(bB, bC, bJ) << endl;
	system("pause");
	return 0;
}

1018 锤子剪刀布

上一篇:安卓测试


下一篇:app测试中ios和Android的区别: