1132:石头剪子布

方法一:二维数组

#include<iostream>
using namespace std;
int w[4][4];
int mmm(char x1[])
{
	switch(x1[0])
	{
		case 'R':
		  return 1;
		case 'S':
		  return 2;
		case 'P':
		  return 3;
		    
	}
}
void mmm2()
{ 
	w[1][1]=w[2][2]=w[3][3]=0;
	w[1][2]=w[2][3]=w[3][1]=1;
	w[2][1]=w[3][2]=w[1][3]=-1;
			
}
int main()
{
	mmm2();
	char S1[100],S2[100];
	int n1,n2;
	int N;
	cin>>N;
 for(int i=0;i<N;i++)
 {  
    cin>>S1>>S2;
    n1=mmm(S1);//如果S1为Rock,则S[0]为R,所有n1=1 
	n2=mmm(S2);
	if(w[n1][n2]==0)
	{
		cout<<"Tie"<<endl;
	}
	else if(w[n1][n2]==1)
	{
		cout<<"Player1"<<endl;
	}
	else
	{
		cout<<"Player2"<<endl;
	}	
  }
	return 0;
 } 

方法二:string类

#include<iostream>
using namespace std;
int main()
{
	int N;
	cin>>N;
	string S1;
	string S2;
	for(int i=1;i<=N;i++)
	{
	    cin>>S1>>S2;
		if(S1=="Rock"&&S2=="Scissors")
		{
			cout<<"Player1"<<endl;
		}
		else if(S1=="Scissors"&&S2=="Paper")
		{
			cout<<"Player1"<<endl;
		}
		else if(S1=="Paper"&&S2=="Rock")
		{
			cout<<"Player1"<<endl;
		}
		else if(S1==S2)
		{
			cout<<"Tie"<<endl;
		 } 
		 else
		 {
		 	cout<<"Player2"<<endl;
		 }
	}
	return 0;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值