/ Vijos / 讨论 / 游戏 /

石头剪刀布

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,s=0,t;
    cout<<"请选择计算机的速度,一个整数,越大越慢。";
    cin>>t;
    for(;;)
    {
        cout<<"请选择出什么:\n1.石头\n2.剪刀\n3.布\n4.不玩了\n";
        for(int i=1;i<=t;i++)
          b=rand()%3;
        b+=1;
        cin>>a;
        if(a==4)
          break;
        if(b==1)
          cout<<"计算机出石头,";
        if(b==2)
          cout<<"计算机出剪刀,";
        if(b==3)
          cout<<"计算机出布,";
        if(a+1==b||a-2==b) 
          cout<<"你赢了!!\n";
        if(a-1==b||a+2==b) 
          cout<<"你输了!!\n";
        if(a==b)
          cout<<"平局。。\n";
        s++; 
    }
    cout<<"下次再来哟~~"; 
    return 0;
}

3 条评论

  • @ 2020-03-13 19:22:51
    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 200 + 10;
    int n, na, nb, a[MAXN], b[MAXN], cnta, cntb;
    int vs[5][5] = {{0,0,1,1,0},{1,0,0,1,0},{0,1,0,0,1},{0,0,1,0,1},{1,1,0,0,0}}; //得分表的处理 
    int main()
    {
        cin >> n >> na >> nb;
        for(int i = 0; i < na; i++) cin >> a[i];
        for(int i = 0; i < nb; i++) cin >> b[i];
        for(int i = 0; i < n; i++)
        {
            cnta += vs[a[i % na]][b[i % nb]]; //周期循环 
            cntb += vs[b[i % nb]][a[i % na]];
        }
        cout << cnta << " " << cntb << endl;
        return 0;
    }
    

    详情请见升级版

  • @ 2020-02-01 12:42:12

    哈哈,不错

  • @ 2020-01-09 12:58:05

    \(\huge\color{Red}\texttt{good}\)

  • 1