1019:石头剪刀布
2013-07-20 20:53
281 查看
1.题目:
用R代表石头,S代表剪子,P代表布。
每组输入样例的第一行是一个整数n(0<n<100),表示游戏次数。
接下来n行,每行由两个字母组成,两个字母之间用一个空格分隔,这些字母只会是R,S或P。
第一个字母表示Player1的选择,第二个字母表示Player2的选择。
2
R P
S R
3
P P
R S
S R
1
P R
TIE
Player 1
2.代码一:
代码二:
题目描述
现在有两个人在玩石头剪子布游戏,请你判断最后谁赢了。用R代表石头,S代表剪子,P代表布。
输入格式
输入的第一行是一个整数t(0<t<1000),表示测试样例的数目。每组输入样例的第一行是一个整数n(0<n<100),表示游戏次数。
接下来n行,每行由两个字母组成,两个字母之间用一个空格分隔,这些字母只会是R,S或P。
第一个字母表示Player1的选择,第二个字母表示Player2的选择。
输出
对于每组输入样例,输出获胜方的名字(Player1或Player2),如果平均,则输出TIE。样例输入
32
R P
S R
3
P P
R S
S R
1
P R
样例输出
Player 2TIE
Player 1
2.代码一:
#include <iostream> using namespace std; int main() { int t, n, score1, score2; char a, b; cin >> t; while (t--) { cin >> n; score1 = score2 = 0; while (n--) { cin >> a >> b; if (a == b) { score1++; score2++; } else if (a == 'R' && b == 'S') score1++; else if (a == 'S' && b == 'R') score2++; else if (a == 'P' && b == 'R') score1++; else if (a == 'R' && b == 'P') score2++; else if (a == 'S' && b == 'P') score1++; else if (a == 'P' && b == 'S') score2++; } if (score1 > score2) cout << "Player 1"; else if (score1 == score2) cout << "TIE"; else if (score1 < score2) cout << "Player 2"; cout << endl; } return 0; }
代码二:
#include<stdio.h> int main() { int t, n, s1, s2; char a, b; scanf("%d", &t); while (t--) { scanf("%d%*c", &n); s1 = s2 = 0; while (n--) { scanf("%c %c%*c", &a, &b); if ((a == 'R' && b == 'S') || (a == 'S' && b == 'P') || (a == 'P' && b == 'R')) s1++; else if ((b == 'R' && a == 'S') || (b == 'S' && a == 'P') || (b == 'P' && a == 'R')) s2++; else { s1++; s2++; } } if (s1 > s2) printf("Player 1\n"); else if (s1 < s2) printf("Player 2\n"); else printf("TIE\n"); } return 0; }
相关文章推荐
- 北大1019
- POJ_1019
- ZOJ1019 Illusive Chase
- poj 1019
- nyist 413 && poj 1019 Number Sequence
- bjtuOJ1019 Robot
- hdu 1019 求多个数的最小公约数
- POJ 1019 Number Sequence
- 猜拳(石头剪刀布)
- POJ 1019 Number Sequence
- HDOJ 1019 Least Common Multiple
- HOJ 1019 Grandpa's Other Estate
- poj1019(数学)
- C语言小程序(七)、石头剪刀布
- 【HDOJ】1019 -> Least Common Multiple
- 1019. General Palindromic Number (20)
- pat basic level 1019
- 1019石头、剪刀、布
- Pat(Basic Level)Practice--1019(数字黑洞)
- POJ 1019 许久之前,觉得这真是一道神题呢。。 递推+二分