NOJ1090Rock, Paper, Scissors——水题

74 篇文章 0 订阅

Rock, Paper, Scissors

时间限制(普通/Java):1500MS/10000MS          运行内存限制:65536KByte
总提交:198            测试通过:84

描述

Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a fist (rock), open hand (paper), or two-finger V (scissors). If both players show the same gesture, they try again. They continue until there are two different gestures. The winner is then determined according to the table below:
 
Rock beats Scissors    
Paper beats Rock    
Scissors beats Paper  
Your task is to take a list of symbols representing the gestures of two players and determine how many games each player wins.
In the following example:

Turn     : 1 2 3 4 5
Player 1 : R R S R S
Player 2 : S R S P S
Player 1 wins at Turn 1 (Rock beats Scissors), Player 2 wins at Turn 4 (Paper beats Rock), and all the other turns are ties.

输入

The input contains between 1 and 20 pairs of lines, the first for Player 1 and the second for Player 2. Both player lines contain the same number of symbols from the set {'R', 'P', 'S'}.  The number of symbols per line is between 1 and 75, inclusive.  A pair of lines each containing the single character 'E' signifies the end of the input.

输出

For each pair of input lines, output a pair of output lines as shown in the sample output, indicating the number of games won by each player.

样例输入

RRSRS
SRSPS
PPP
SSS
SPPSRR
PSPSRS
E
E

样例输出

P1: 1
P2: 1
P1: 0
P2: 3
P1: 2
P2: 1

题目来源

ACM Mid-Central Regional 2009


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

char p1[75];
char p2[75];
int num, p1_win, p2_win;

int main()
{
	while(scanf("%s%s",p1,p2) && p1[0] != 'E')
	{
		//printf("out:%s %s\n",p1,p2);
		num = strlen(p1); 
		p1_win = p2_win = 0;
		for(int i=0;i<num;i++)
		{
			if(p1[i] != p2[i])
			{
				if(p1[i] == 'R')
				{
					if(p2[i] == 'P') p2_win++;
					else p1_win++;
				}
				else if(p1[i] == 'P')
				{
					if(p2[i] == 'R') p1_win++;
					else p2_win++;
				}
				else // p1[i] == 'S'
				{
					if(p2[i] == 'P') p1_win++;
					else p2_win++;
				}
			}
		}
		printf("P1: %d\nP2: %d\n",p1_win,p2_win);
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值