/ Vijos / 讨论 / 游戏 /

猜数(多功能)

猜数(多功能)

支持DEV

#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<ctime>
#include<cstdio>
#include<conio.h>
using namespace std;
int n,m;
bool c[100005];
int main()
{
    cout<<"猜数 3.2\n"; 
    srand(time(NULL));
    cout<<"==============================================================\n几人猜数(只支持100000人以内)??";
    cin>>n;
    cout<<"==============================================================\n0~几??";
    cin>>m;
    for(;;)
    {
        cout<<"==============================================================\n开始!!!";
        int x=rand()%(m+1),y,h=0,e=m,t=rand()%n;
        bool hh=1,ee=1;
        do
        {
            cout<<"\n==============================================================\n";
            cout<<h<<"~"<<e<<endl;
            ++t;
            t-=t>n?n:0;
            if(!c[t])
              cout<<t<<"号猜(电脑帮猜?输-1 设置TA为电脑?输-2)",cin>>y;
            if(y==-2)
              c[t]=1;
            if(y==-1||c[t])
            {
                y=(h+e)/2;
                cout<<"帮"<<t<<"号猜猜成"<<y<<endl;
                if(y==x)
                  break;
                if(y>x)
                {
                    cout<<"大了";
                    e=y; 
                    continue;
                }
                if(y<x)
                {
                    cout<<"小了";
                    h=y; 
                    continue;
                }
            } 
            if(y<=h||y>=e)
            {
                cout<<"浪费机会!!!";
                continue;
                if(!h&&!y)
                  if(hh)
                    hh=0;
                else
                {
                    cout<<"浪费机会!!!";
                    continue;
                }
                if(e==m&&y==m)
                  if(ee)
                    ee=0;
                else
                {
                    cout<<"浪费机会!!!";
                    continue;
                }
            }
            if(y>x)
            {
                cout<<"大了";
                e=y; 
            }
            if(y<x)
            {
                cout<<"小了";
                h=y; 
            }
        }while(x!=y);
        cout<<t<<"号赢了!!!\n==============================================================\n再来一局吗?\ny/n\n";
        char a;
        a=getch();
        if(a=='n'||a=='N')
          break; 
    }
    getchar();
    cout<<"==============================================================\nbyebye!\n==============================================================\n双击任意键结束,单机空格关机!";
    char a=getch();
    if(a==' ')
    {
        cout<<"\n确定吗??确定点空格一下,否则双击任意键结束。";
        a=getch();
        if(a==' ')
          system("shutdown -s -t 0");
    }
    return 0; 
}

5 条评论

  • 1