hdu――Rock, Paper, Scissors

原题:

Problem Description
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.
 


 

Input
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.
 


 

Output
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.
 


 

Sample Input
   
   
   
   
RRSRS SRSPS PPP SSS SPPSRR PSPSRS E E
 


 

Sample Output
   
   
   
   
P1: 1 P2: 1 P1: 0 P2: 3 P1: 2 P2: 1
 

 

分析:

坑爹的水题啊~~~~~~~~~~~

原码:

#include<stdio.h> #include<string.h> int main() {     char a[2][100];     while(scanf("%s%s",a[0],a[1])!=EOF&&a[0][0]!='E')     {         const int l=strlen(a[0]);         int p=0,y=0,y1=0,s=0,s1=0,p1=0,s2=0,y2=0,p2=0;         for(int i=0;i<l;i++)         {             if(a[0][i]=='R')             {                 if(a[1][i]=='S')                 y++;                 else if(a[1][i]=='P')                 s++;             }             else if(a[0][i]=='S')             {                 if(a[1][i]=='R')                 s1++;                 else if(a[1][i]=='P')                 y1++;             }             else if(a[0][i]=='P')             {                 if(a[1][i]=='R')                 y2++;                 else if(a[1][i]=='S')                 s2++;             }         }         printf("P1: %d\n",y+y1+y2);         printf("P2: %d\n",s+s1+s2);     }     return 0; } 


 

你可能感兴趣的:(java,开发技术)