zoukankan      html  css  js  c++  java
  • Rock,Paper,Scissors 水NOJ 1090

    Rock, Paper, Scissors

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

    题目描述

    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

    水题就不废话了~

    实现代码:

    <span style="font-size:12px;">#include<iostream>
    #include<cstdlib>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    char a[76],b[76];
    int main()
    {
        while(scanf("%s%s",&a,&b)&&!(a[0]=='E'&&b[0]=='E'))
        {
            int len=strlen(a);
            int aa=0,bb=0;
            for(int i=0;i<len;i++)
            {
                if(a[i]=='R')
                {
                    if(b[i]=='S')
                    {
                        aa++;
                    }
                    if(b[i]=='P')
                    {
                        bb++;
                    }
                }
                else if(a[i]=='P')
                {
                    if(b[i]=='R')
                    {
                        aa++;
                    }
                    if(b[i]=='S')
                    {
                        bb++;
                    }
                }
                else if(a[i]=='S')
                {
                    if(b[i]=='P')
                    {
                        aa++;
                    }
                    if(b[i]=='R')
                    {
                        bb++;
                    }
                }
            }
            printf("P1: %d
    P2: %d
    ",aa,bb);
        }
    }</span>

    Rock, Paper, Scissors

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

    题目描述

    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

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    django框架——十二
    django框架——十一
    请简述一下你所了解的数据源控件有哪些
    在ASP.NET中,<%= %>和<%# %>有什么区别
    请解释ASP.NET中的web页面与其隐藏类之间的关系
    什么是viewstate,能否禁用?是否所用控件都可以禁用
    WEB控件及HTML服务端控件能否调用客户端方法?如果能,请解释如何调用
    静态类和静态方法的好处
    请写出在ASP.NET中常用的几种页面间传值的方法,并说出它们的特点。
    连接数据库主要有哪几个对象
  • 原文地址:https://www.cnblogs.com/Tobyuyu/p/4965497.html
Copyright © 2011-2022 走看看