c++石头剪子布

描述

石头剪子布,是一种猜拳游戏。起源于中国,然后传到日本、朝鲜等地,随着亚欧贸易的不断发展它传到了欧洲,到了近现代逐渐风靡世界。简单明了的规则,使得石头剪子布没有任何规则漏洞可钻,单次玩法比拼运气,多回合玩法比拼心理博弈,使得石头剪子布这个古老的游戏同时用于“意外”与“技术”两种特性,深受世界人民喜爱。

游戏规则:石头打剪刀,布包石头,剪刀剪布。

现在,需要你写一个程序来判断石头剪子布游戏的结果。

输入

输入包括N+1行:
第一行是一个整数N,表示一共进行了N次游戏。1 <= N <= 100。
接下来N行的每一行包括两个字符串,表示游戏参与者Player1,Player2的选择(石头、剪子或者是布):
S1 S2
字符串之间以空格隔开S1,S2只可能取值在{"Rock", "Scissors", "Paper"}(大小写敏感)中。

输出

输出包括N行,每一行对应一个胜利者(Player1或者Player2),或者游戏出现平局,则输出Tie。

样例输入

3
Rock Scissors
Paper Paper
Rock Paper

样例输出

Player1
Tie
Player2

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char R[10]={"Rock"};
char S[10]={"Scissors"};
char P[10]={"Paper"}; 
int main(){
	int N;
	cin>>N;
	char player1[2000];
	char player2[2000];
	int count[105]={0};
	for(int i=0;i<N;i++){
		cin>>player1>>player2;
		if(strcmp(player1,R)==0&&strcmp(player2,R)==0){
			count[i]+=3;
		} 
		if(strcmp(player1,R)==0&&strcmp(player2,S)==0){
			count[i]+=1;
		}
		if(strcmp(player1,R)==0&&strcmp(player2,P)==0){
			count[i]+=2;
		}
		if(strcmp(player1,S)==0&&strcmp(player2,S)==0){
			count[i]+=3;
		}
		if(strcmp(player1,S)==0&&strcmp(player2,R)==0)
		{
			count[i]+=2;
		}
		if(strcmp(player1,S)==0&&strcmp(player2,P)==0){
			count[i]+=1;
		}
		if(strcmp(player1,P)==0&&strcmp(player2,P)==0){
			count[i]+=3;
		}
		if(strcmp(player1,P)==0&&strcmp(player2,S)==0){
			count[i]+=2;
		}
		if(strcmp(player1,P)==0&&strcmp(player2,R)==0){
			count[i]+=1;
		}
	} 
for(int i=0;i<N;i++){
	if(count[i]==1){
		cout<<"Player1"<<endl;
	}
	if(count[i]==2){
		cout<<"Player2"<<endl;
	}
	if(count[i]==3){
		cout<<"Tie"<<endl;
	}
}
	return 0;
}

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值