现在的位置: 首页 > 综合 > 正文

hdu2164 Rock, Paper, or Scissors? 玩石头、剪刀、布游戏…

2013年02月05日 ⁄ 综合 ⁄ 共 629字 ⁄ 字号 评论关闭

#include <iostream>
#include <string>
using namespace std;

string P("P");
string R("R");
string S("S");

void getinfor(string &t,string &t1)
{
    cin >> t >> t1;
}

bool process(int &p1,int &p2,string tm,string tm1)
{
    if(tm == P)
    {
        if(tm1 == R)
        {
            p1++;
        }
        else if(tm1 == S)
        {
            p2++;
        }
    }
    else if(tm == R)
    {
        if(tm1 == P)
        {
            p2++;
        }
        else if(tm1 == S)
        {
            p1++;
        }
    }
    else
    {
        if(tm1 == P)
        {
            p1++;
        }
        else if(tm1 == R)
        {
            p2++;
        }
    }
   return true;
}

int main()
{
    int test;
    int n;    
    cin >> test;
    while(test--)
    {
        cin >> n;
        string temp;
        string temp1;
        int player1 = 0;
        int player2 = 0;
        for(int i = 0; i < n; ++i)
        {
            getinfor(temp,temp1);
            process(player1,player2,temp,temp1);
        }
        if(player1 == player2)
        {
            puts("TIE");
        }
        else if(player1 > player2)
        {
            puts("Player 1");
        }
        else
        {
            puts("Player 2");
        }
    }
    return 0;
}

 

抱歉!评论已关闭.