描述

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

#include<iostream>
#include<string>
using namespace std; void compare(char a,char b,int &count1,int &count2)
{
if(a=='R')
{
if(b=='S') count1++;
if(b=='P') count2++;
}
if(a=='P')
{
if(b=='R') count1++;
if(b=='S') count2++;
}
if(a=='S')
{
if(b=='P') count1++;
if(b=='R') count2++;
}
}
int main()
{
string s1,s2;
while(cin>>s1>>s2&&(s1!="E"&&s2!="E"))
{
int len=s1.length();
int i;
int count1=0;
int count2=0;
for(i=0;i<len;i++)
{
compare(s1[i],s2[i],count1,count2);
}
cout<<"P1: "<<count1<<endl;
cout<<"P2: "<<count2<<endl;
}
return 0;
}

  

1090-Rock, Paper, Scissors的更多相关文章

  1. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  2. SDUT 3568 Rock Paper Scissors 状压统计

    就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...

  3. FFT(Rock Paper Scissors Gym - 101667H)

    题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...

  4. Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数

    Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...

  5. Gym101667 H. Rock Paper Scissors

    将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...

  6. 【题解】CF1426E Rock, Paper, Scissors

    题目戳我 \(\text{Solution:}\) 考虑第二问,赢的局数最小,即输和平的局数最多. 考虑网络流,\(1,2,3\)表示\(Alice\)选择的三种可能性,\(4,5,6\)同理. 它们 ...

  7. 题解 CF1426E - Rock, Paper, Scissors

    一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...

  8. HDOJ(HDU) 2164 Rock, Paper, or Scissors?

    Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...

  9. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

随机推荐

  1. 类似微博菜单 ,用swift语言编写

    自定义tabar搭载界面1.-自定义标题按钮_如图  2.10-导航条按钮封装 演示如下 源代码下载DSWeibo.zip

  2. ViewState原理

    1.IsPostBack原理 1.1 所有的服务端控件,都必须放在runat="server"的表单里面,runat="server"的表单会生成__VIEWS ...

  3. Extjs3笔记 fbar

    在项目中会遇到在grid右下角显示合计之类的显示. 之前使用过的方式: 1.用width强制顶过去. 2.利用css来控制. 弊端: 利用第一种方式:导致调整窗口大小时会导致合计不能根据窗体的大小变化 ...

  4. onActivityResult调用不到的问题

    有可能是调用时机不对,请转移到: http://www.cnblogs.com/shaweng/p/3875825.html 还有可能是Activity的launchmode导致的 使用 androi ...

  5. Java多线程编程总结(学习博客)

    Java多线程编程总结:网址:http://lavasoft.blog.51cto.com/62575/27069/

  6. 函数-头文件//Calculator.h

    // // Calculator.h // 函数-头文件 // // Created by zhangxueming on 15/6/2. // Copyright (c) 2015年 zhangxu ...

  7. (转)传统MySQL+ Memcached架构遇到的问题

    实际MySQL是适合进行海量数据存储的,通过Memcached将热点数据加载到cache,加速访问,很多公司都曾经使用过这样的架构,但随着业务数据量的不断增加,和访问量的持续增长,我们遇到了很多问题: ...

  8. hibernate初探

    1.在MyEclipse Datebase Explorer 页面中新创建一个连接数据库“DB Browser”的XX,如起名“register”2.新建项目->右键Properties-> ...

  9. ThinkPHP3.2 加载过程(四)

    前言: 由于比较懒散,但是又是有点强迫症,所以还是想继续把ThinkPHP3.2的加载过程这个烂尾楼补充完整. ========================================分割线= ...

  10. jQuery关于导航条背景切换

    效果如下: <DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jqu ...