返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     //剪刀石頭布
  8.     string win[3]={"你贏","電腦贏","平手"};
  9.     int player=0;
  10.     int com=0;
  11.     cout<<"輸入你要的拳(1.剪刀2.石頭3.布)"<<endl;
  12.     cin>>player;
  13.     cout<<"電腦出拳中..."<<endl;
  14.     srand(time(NULL));
  15.     com=(rand()%3)+1;
  16.     if(player==1&&com==3)
  17.     {
  18.         cout<<win[0]<<endl;
  19.     }
  20.     if(player==1&&com==2)
  21.     {
  22.         cout<<win[1]<<endl;
  23.     }
  24.     if(player==2&&com==1)
  25.     {
  26.         cout<<win[0]<<endl;
  27.     }
  28.     if(player==2&&com==3)
  29.     {
  30.         cout<<win[1]<<endl;
  31.     }
  32.     if(player==3&&com==2)
  33.     {
  34.         cout<<win[0]<<endl;
  35.     }
  36.     if(player==2&&com==3)
  37.     {
  38.         cout<<win[1]<<endl;
  39.     }
  40.     else
  41.     {
  42.         cout<<win[2]<<endl;
  43.     }
  44.     system("PAUSE");
  45.     return 0;
  46. }
複製代碼

TOP

返回列表