zoukankan      html  css  js  c++  java
  • 人机对战石头剪刀布代码

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
        int com,user,ans;
        double a=0,b=0;
        char c;
        srand((unsigned)time(NULL));//rand函数
        long long n;
        char p[200];
        cout<<"请输入您的大名:"<<endl;
        scanf("%s",&p);
        cout<<"您要玩的次数:";
        cin>>n;
        printf("1.剪刀 2.石头 3.布:");
        for(int i=1; i<=n; i++) {
            scanf("%d",&user);
            cout<<endl;
            com=rand()%3+1;
            printf("电脑出%s
    ",com==1?"剪刀":com==2?"石头":"");
            ans=com-user ;//用两次相减结果来判断胜负
            if(ans==0) {
                printf("打平了,在试一次就赢了 ! ! 
    ");
                a+=0.5,b+=0.5;
            } else if(ans==1||ans==-2) {
                printf("很遗憾,您输了,加油 ! ! !
    ");
                a++;
            } else if(ans==-1||ans==2) {
                printf("您赢了,乘胜追击 ! !
    ");
                b++;
            }
        }
        cout<<endl;
        cout<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"最终比分:" <<endl;
        cout<<"电脑"<<" "<<a<<" "<<":"<<" "<<b<<" "<<p<<endl;
        if(a>b)
            cout<<"很遗憾,你输了,双击f11在来一次哦 ! !" ;
        else if(a==b)
            cout<<"打平了,在试一次一定能赢,双击f11在来一次哦 ! !" ;
        else
            cout<<"你赢了,按两次f11乘胜追击哦 ! ! !";
        return 0;
    }
  • 相关阅读:
    Docker管理应用数据
    Docker Swarm mode
    Docker Compose file
    Docker Compose 多容器应用
    MySQL中ORDER BY与LIMIT一起使用(有坑)
    Docker for Java Developers
    Nifi 模板
    Nifi InvokeHttp processor
    Mac上连接nifi
    前端开发环境webstorm搭建
  • 原文地址:https://www.cnblogs.com/kevin6666/p/11347139.html
Copyright © 2011-2022 走看看