本文主要是介绍PAT B1018 -- 锤子剪刀布,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
牛客网PAT乙级第八题,锤子剪刀布,题目描述大致如下:
输入第一行正整数N(N<=105),代表交锋次数,接下来N行输入交锋信息,格式"甲 乙",C代表锤子,B代表布,J代表剪刀。
输出第1,2行分别给出甲和乙的胜,负,平的次数,数字间空格分离,第三行给出两个字母,代表甲和乙获胜次数最多的手势。
空格分隔,如果解不唯一,输出字母序最小的解。
代码如下:
#include <iostream>using namespace std;char FindVictoryWay(int shitou, int jiandao, int bu)
{if (shitou > jiandao){if (bu >= shitou){return 'B';}else{return 'C';}}else if (shitou == jiandao){if (shitou > bu){return 'C';}else{return 'B';}}else{if (jiandao > bu){return 'J';}else{return 'B';}}}int main()
{int N;//交锋次数char a_result, b_result;int a_victory = 0, a_ping = 0, b_victory = 0;int a_shitou = 0, a_jiandao = 0, a_bu = 0, b_shitou = 0, b_jiandao = 0, b_bu = 0;char a_winmost, b_winmost;while (cin >> N){for (int i = 0; i < N; i++){cin >> a_result >> b_result;if (a_result == b_result){a_ping++;}else if (((a_result == 'C') && (b_result == 'J')) || ((a_result == 'B') && (b_result = 'C')) || ((a_result == 'J') && (b_result == 'B'))){a_victory++;switch (a_result){case 'C':a_shitou++;break;case 'J':a_jiandao++;break;case 'B':a_bu++;break;default:break;}}else{b_victory++;switch (b_result){case 'C':b_shitou++;break;case 'J':b_jiandao++;break;case 'B':b_bu++;break;default:break;}}}a_winmost = FindVictoryWay(a_shitou, a_jiandao, a_bu);b_winmost = FindVictoryWay(b_shitou, b_jiandao, b_bu);cout << a_victory << " " << a_ping << " " << b_victory << endl;cout << b_victory << " " << a_ping << " " << a_victory << endl;cout << a_winmost << " " << b_winmost << endl;}return 0;
}
这篇关于PAT B1018 -- 锤子剪刀布的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!