zoukankan      html  css  js  c++  java
  • 1132:石头剪子布

    时间限制: 1000 ms 内存限制: 65536 KB
    提交数: 9833 通过数: 5176

    【题目描述】

    石头剪子布,是一种猜拳游戏。起源于中国,然后传到日本、朝鲜等地,随着亚欧贸易的不断发展它传到了欧洲,到了近现代逐渐风靡世界。简单明了的规则,使得石头剪子布没有任何规则漏洞可钻,单次玩法比拼运气,多回合玩法比拼心理博弈,使得石头剪子布这个古老的游戏同时用于“意外”与“技术”两种特性,深受世界人民喜爱。

    游戏规则:石头打剪刀,布包石头,剪刀剪布。

    现在,需要你写一个程序来判断石头剪子布游戏的结果。

    【输入】

    第一行是一个整数N,表示一共进行了N次游戏。1 ≤ N ≤ 100。

    接下来N行的每一行包括两个字符串,表示游戏参与者Player1,Player2的选择(石头、剪子或者是布):

    S1 S2

    字符串之间以空格隔开S1,S2只可能取值在{“Rock”, “Scissors”, “Paper”}(大小写敏感)中。

    【输出】

    输出包括N行,每一行对应一个胜利者(Player1或者Player2),或者游戏出现平局,则输出Tie。

    【输入样例】

    3
    Rock Scissors
    Paper Paper
    Rock Paper

    【输出样例】

    Player1
    Tie
    Player2

    【来源】

    No

    code

    /*
                                    ^....0
                                   ^ .1 ^1^
                                   ..     01
                                  1.^     1.0
                                 ^ 1  ^    ^0.1
                                 1 ^        ^..^
                                 0.           ^ 0^
                                 .0            1 .^
                                 .1             ^0 .........001^
                                 .1               1. .111100....01^
                                 00             ^   11^        ^1. .1^
                                 1.^                              ^0  0^
                                   .^                                 ^0..1
                                   .1                                   1..^
                                 1 .0                                     ^  ^
                                ^ 00.                                     ^^0.^
                                 1 ^ 0                                     ^^110.^
                               0.   0 ^                                    ^^^10.01
                       ^^     010^   1 1                                   ^^^1110.1
                       0001  10 0   ^ 1.1                                   ^^^1111110
                       0^ 10 . 01   ^^  ^^                                   ^^^1111^1.^           ^^^
                       10  10^ 0^                                             ^^111^^^0.1^       1....^
                        11     0                                               ^^11^^^ 0..  ....1^   ^ ^
                        1.     0^                                               ^11^^^ ^ 1 111^     ^ 0.
                       10   00 11                                               ^^^^^   1 0           1.
                       0^  ^0  ^0                                                ^^^^    0            0.
                       0^  1.0  .^                                               ^^^^    1 1          .0
                       ^.^  ^^  0^                             ^1                ^^^^     0.         ^.1
                       1 ^      11                             1.                ^^^     ^ ^        ..^
                      ^..^      ^1                             ^.^               ^^^       .0       ^.0
                      0..^      ^0                              01               ^^^       ..      0..^
                     1 ..        .1                             ^.^              ^^^       1 ^  ^0001
                    ^  1.        00                              0.             ^^^        ^.0 ^.1
                    . 0^.        ^.^                             ^.^            ^^^         ..0.0
                   1 .^^.         .^                  1001        ^^            ^^^         . 1^
                   . ^ ^.         11                0.    1         ^           ^^          0.
                    0  ^.          0              ^0       1                   ^^^          0.
                  0.^  1.          0^             0       .1                   ^^^          ..
                  .1   1.          00            .        .1                  ^^^           ..
                 1      1.         ^.           0         .^                  ^^            ..
                 0.     1.          .^          .         0                                  .
                 .1     1.          01          .        .                                 ^ 0
                ^.^     00          ^0          1.       ^                                 1 1
                .0      00           .            ^^^^^^                                   .
                .^      00           01                                                    ..
               1.       00           10                                                   1 ^
              ^.1       00           ^.                                            ^^^    .1
              ..        00            .1                                        1..01    ..
             1.1         00           1.                                       ..^      10
            ^ 1^         00           ^.1                                      0 1      1
            .1           00            00                                       ^  1   ^
             .           00            ^.^                                        10^  ^^
           1.1           00             00                                              10^
           ..^           1.             ^.                                               1.
          0 1            ^.              00                 00                            .^
            ^            ^.              ^ 1                00   ^0000^     ^               01
         1 0             ^.               00.0^              ^00000   1.00.1              11
         . 1              0               1^^0.01                      ^^^                01
          .^              ^                1   1^^                                       ^.^
        1 1                                                                              0.
        ..                                                                              1 ^
         1                                                                               1
       ^ ^                                                                             .0
       1                                                                             ^ 1
       ..                                                          1.1            ^0.0
      ^ 0                                                           1..01^^100000..0^
      1 1                                                            ^ 1 ^^1111^ ^^
      0 ^                                                             ^ 1      1000^
      .1                                                               ^.^     .   00
      ..                                                                1.1    0.   0
      1.                                                                  .    1.   .^
      1.                                                                 1    1.   ^0
     ^ .                                                                 ^.1 00    01
     ^.0                                                                  001.     .^
     */
    // An_all_in_one_book_on_Informatics —— 1132.cpp created by VB_KoKing on 2019,04,28,12.
    /* Procedural objectives:
    石头剪刀布
     Procedural thinking:
     1.读入数字n
     2.循环读入每局双方玩家的选择
     Functions required by the program:
     1.判断胜负的函数judge(),需要传入两个字符串,int类型,返回值:0——平局,1——玩家1胜,2代表玩家2胜。
     Variables required by the program:
     1.字符串数组str[100]
     2.变量n
    */
    /* My dear Max said:
    "I like you,
    So the first bunch of sunshine I saw in the morning is you,
    The first hurricane that passed through your ear is you,
    The first star you see is also you.
    The world I see is all your shadow."
    
    FIGHTING FOR OUR FUTURE!!!
    */
    #include <iostream>
    #include <string>
    using namespace std;
    int check(string str1,string str2)
    {
        if (str1==str2) return 0;
        if (str1=="Rock")
        {
            if (str2=="Scissors") return 1;
            if (str2=="Paper") return 2;
        }
        if (str1=="Scissors")
        {
            if (str2=="Paper") return 1;
            if (str2=="Rock") return 2;
        }
        if (str1=="Paper")
        {
            if (str2=="Rock") return 1;
            if (str2=="Scissors") return 2;
        }
    }
    int main()
    {
        int n;
        cin>>n;
        string str1[100],str2[100];
        for (int i = 0; i < n; i++)
            cin>>str1[i]>>str2[i];
        for (int i = 0; i < n; i++)
        {
            if (check(str1[i],str2[i])==0) cout<<"Tie"<<endl;
            if (check(str1[i],str2[i])==1) cout<<"Player1"<<endl;
            if (check(str1[i],str2[i])==2) cout<<"Player2"<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    PAT (Advanced Level) 1060. Are They Equal (25)
    PAT (Advanced Level) 1059. Prime Factors (25)
    PAT (Advanced Level) 1058. A+B in Hogwarts (20)
    PAT (Advanced Level) 1057. Stack (30)
    PAT (Advanced Level) 1056. Mice and Rice (25)
    PAT (Advanced Level) 1055. The World's Richest (25)
    PAT (Advanced Level) 1054. The Dominant Color (20)
    PAT (Advanced Level) 1053. Path of Equal Weight (30)
    PAT (Advanced Level) 1052. Linked List Sorting (25)
    PAT (Advanced Level) 1051. Pop Sequence (25)
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12338404.html
Copyright © 2011-2022 走看看