zoukankan      html  css  js  c++  java
  • HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164

    Problem Description
    Rock, Paper, Scissors is a two player game, where each player simultaneously chooses one of the three items after counting to three. The game typically lasts a pre-determined number of rounds. The player who wins the most rounds wins the game. Given the number of rounds the players will compete, it is your job to determine which player wins after those rounds have been played. 

    The rules for what item wins are as follows:

    ?Rock always beats Scissors (Rock crushes Scissors)
    ?Scissors always beat Paper (Scissors cut Paper)
    ?Paper always beats Rock (Paper covers Rock) 
     
    Input
    The first value in the input file will be an integer t (0 < t < 1000) representing the number of test cases in the input file. Following this, on a case by case basis, will be an integer n (0 < n < 100) specifying the number of rounds of Rock, Paper, Scissors played. Next will be n lines, each with either a capital R, P, or S, followed by a space, followed by a capital R, P, or S, followed by a newline. The first letter is Player 1抯 choice; the second letter is Player 2抯 choice.

     
    Output
    For each test case, report the name of the player (Player 1 or Player 2) that wins the game, followed by a newline. If the game ends up in a tie, print TIE.
     
    Sample Input
    3
    2
    R P
    S R
    3
    P P
    R S
    S R
    1
    P R
     
    Sample Output
    Player 2
    TIE
    Player 1
     
    代码:
    #include <bits/stdc++.h>
    using namespace std;
    
    char p1[1111], p2[1111];
    
    int cmp(char a, char b) {
    
        if(a == 'S') {
            if(b == 'P') return 2;
            if(b == 'R') return 1;
        }
    
        if(a == 'R') {
            if(b == 'S') return 2;
            if(b == 'P') return 1;
        }
    
        if(a == 'P') {
            if(b == 'R') return 2;
            if(b == 'S') return 1;
        }
    }
    
    int main() {
        int T;
        scanf("%d", &T);
        while(T --) {
            int x;
            scanf("%d", &x);
            int cnt = 0, ans = 0;
            getchar();
            for(int i = 1; i <= x; i ++) {
                scanf("%c %c", &p1[i], &p2[i]);
                getchar();
                if(cmp(p1[i], p2[i]) == 2)
                    cnt ++;
                else if(cmp(p1[i], p2[i]) == 1)
                    ans ++;
            }
    
            if(cnt > ans)
                printf("Player 1
    ");
            else if(cnt == ans)
                printf("TIE
    ");
            else
                printf("Player 2
    ");
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    ASP.NET动态加载用户控件的页面生成过程
    简单的flash与asp.net通信(LoadVars类)
    转 推荐两本FLASH RIA应用开发方面的书籍
    关于代码加密解密保护
    转 利用 SharpZipLib方便地压缩和解压缩文件
    在C#中应用哈希表(Hashtable)
    C#中解析并运行一个本地命令行
    About Windows Live Writer
    安装sql server 2008,提示要删除SQL Server 2005 Express 工具,可我根本没装
    [转] C#中的null
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9417374.html
Copyright © 2011-2022 走看看