c++小さいゲーム:洛谷宝くじ

73347 ワード

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int money=100;
int t=0;
int tt=-1;
int v;
int d;
void borrow()
{
    if(tt!=-1)
    {
        cout<<"       "<<endl;
        return;
    }
    cout<<"      ?"<<endl;
    cin>>v;
    if (d==1||d==2)
    {
        if (v>1000) cout<<"        !"<<endl,cout<<"      ?"<<endl,cin>>v;
        if (v<=1000) money+=v,cout<<"10      "<<2*v<<"  "<<endl;
        return;
    }
    else
    {
        if (v>100) cout<<"        !"<<endl,cout<<"      ?"<<endl,cin>>v;
        if (v<=100) money+=v,cout<<"10      "<<2*v<<"  "<<endl;
        return;
    }
}
bool pay()
{
    cout<<"      "<<2*v<<endl;
    money-=2*v;
    tt=-1;
    v=0;
    if(money<=0) return false;
    else return true;
}
int main(int argc, char *argv[])
{
    cout<<"        !"<<endl<<endl<<"    :          、  、    、    (        ),"<<endl<<"      。"<<endl<<endl;
    cout<<"     (      ):"<<endl<<"1:  "<<" "<<"2:  "<<" "<<"3:  "<<" "<<"4:  "<<" "<<"5:  "<<endl;
    cin>>d;
    if (d==1) cout<<"     :  "<<endl<<endl;
    if (d==2) cout<<"     :  "<<endl<<endl;
    if (d==3) cout<<"     :  "<<endl<<endl;
    if (d==4) cout<<"     :  "<<endl<<endl;
    if (d==5) cout<<"     :  "<<endl<<endl;
    while(1)
    {
        if (d<1) cout<<"      "<<endl<<"     (      ):"<<endl<<"1:  "<<" "<<"2:  "<<" "<<"3:  "<<" "<<"4:  "<<" "<<"5:  "<<endl,cin>>d;
        if (d>5) cout<<"      "<<endl<<"     (      ):"<<endl<<"1:  "<<" "<<"2:  "<<" "<<"3:  "<<" "<<"4:  "<<" "<<"5:  "<<endl,cin>>d;
        if (d==1 || d==2 || d==3 || d==4 || d==5) break;
    }
    bool flag=true;
    srand(time(0));
    int a[10000];
    int n,p;
    char c[4];
    if (d==1)
    {
        cout<<"         1  ,    5  ,     "<<endl<<"  :10  "<<endl<<"  :20  "<<endl<<"  :100  "<<endl<<"    :1,000  "<<endl<<"   :10,000  "<<endl;
        cout<<"  100  ,      10,000  ,     。"<<endl<<"           ,    。"<<endl;
        cout<<"      (  1,000  ),    , 0。"<<endl<<"   ,        。       ,"<<endl;
        cout<<"          ?(buy/sell)"<<endl;
    }
    if (d==2)
    {
        cout<<"         2  ,    3  ,     "<<endl<<"  :5  "<<endl<<"  :20  "<<endl<<"  :100  "<<endl<<"    :1,000  "<<endl<<"   :10,000  "<<endl;
        cout<<"  100  ,      10,000  ,     。"<<endl<<"           ,    。"<<endl;
        cout<<"      (  1,000  ),    ,  0。"<<endl<<"   ,        。       ,"<<endl;
        cout<<"          ?(buy/sell)"<<endl;
    }
    if (d==3)
    {
        cout<<"       2  ,     "<<endl<<"  :5  "<<endl<<"  :20  "<<endl<<"  :100  "<<endl<<"    :1,000  "<<endl<<"   :10,000  "<<endl;
        cout<<"  100  ,      10,000  ,     。"<<endl<<"           ,    。"<<endl;
        cout<<"      (  100  ),    ,  0。"<<endl<<"   ,        。       ,"<<endl;
        cout<<"          ?(buy/sell)"<<endl;
    }
    if (d==4)
    {
        cout<<"       3  ,     "<<endl<<"  :5  "<<endl<<"  :20  "<<endl<<"  :100  "<<endl<<"    :1,000  "<<endl<<"   :10,000  "<<endl;
        cout<<"  100  ,      100,000  ,     。"<<endl<<"           ,    。"<<endl;
        cout<<"      (  100  ),    ,  0。"<<endl<<"   ,        。       ,"<<endl;
        cout<<"          ?(buy/sell)"<<endl;
    }
    if (d==5)
    {
        cout<<"         5  ,    2  ,     "<<endl<<"  :5  "<<endl<<"  :20  "<<endl<<"  :100  "<<endl<<"    :1,000  "<<endl<<"   :5,000  "<<endl;
        cout<<"  100  ,      100,000  ,     。"<<endl<<"           ,     。"<<endl;
        cout<<"      (  100  ),    ,  0。"<<endl<<"   ,        。       ,"<<endl;
        cout<<"          ?(buy/sell)"<<endl;
    }
    cin>>c;
    if(c[0]=='b'||c[0]=='B')
    {
        while(money>0)
        {
            if (d==1||d==2||d==3) if(money>=10000)
                {
                    cout<<"    ! "<<endl;
                    cout<<"    "<<t<<" "<<endl;
                    system("pause");
                    return 0;
                }
            if (d==4||d==5) if(money>=100000)
                {
                    cout<<"    ! "<<endl;
                    cout<<"    "<<t<<" "<<endl;
                    system("pause");
                    return 0;
                }
            t++;
            cout<<"      ?"<<" "<<"  $"<<money<<endl;
            cin>>n;
            if(n==0)
            {
                if (d=4)
                {
                    borrow();
                    tt=t+7;
                }
                if (d=5)
                {
                    borrow();
                    tt=t+5;
                }
                else
                {
                    borrow();
                    tt=t+10;
                }
            }
            if(t==tt)
            {
                flag=pay();
            }
            if(t==tt-1) cout<<"[  ]        !"<<endl;
            if(flag==false)
            {
                cout<<"         !"<<endl;
                cout<<"    。"<<endl;
                cout<<"    "<<t<<" 。"<<endl;
                system("pause");
                return 0;
            }
            flag=true;
            if(n<0)
            {
                cout<<"       ,             "<<endl;
                system("pause");
            }
            if (d==1) money=money-n;
            if (d==2||d==3) money=money-n*2;
            if (d==4) money=money-n*3;
            if (d==5) money=money-n*5;
            if(money<0)
            {
                cout<<"    。"<<endl;
                cout<<"    "<<t<<" "<<endl;
                system("pause");
                return 0;
            }
            for(int i=0; i<n; i++)
            {
                p=rand()%12000;
                if(p==0)
                {
                    int q=0;
                    q=rand()%4;
                    if(q==1)
                    {
                        cout<<"       !"<<endl;
                        if (d==5) money+=5000;
                        else money+=10000;
                    }
                }
                else if(p>=1&&p<=8)
                {
                    int g=0;
                    g=rand()%2;
                    if(g==0)
                    {
                        cout<<"        ! "<<endl;
                        money+=1000;
                    }
                }
                else if(p>=9&&p<=99)
                {
                    cout<<"      !"<<endl;
                    money+=100;
                }
                else if((p>=100&&p<=399)||(p>1500&&p<=1600))
                {
                    cout<<"       !"<<endl;
                    money+=20;
                }
                else if(p>=400&&p<=1500)
                {
                    cout<<"      !"<<endl;
                    if (d==1) money+=10;
                    else money+=5;
                }
            }
            if(money<=0)
            {
                cout<<"    。"<<endl;
                cout<<"    "<<t<<" 。"<<endl;
                system("pause");
                return 0;
            }
        }
    }
    if(c[0]=='s'||c[0]=='S')
    {
        if (d==1)
        {
            cout<<"  $"<<money<<endl;
            cout<<"    25       。 "<<endl;
            cout<<"               。 "<<endl;
            money-=25;
        }
        if (d==2)
        {
            cout<<"  $"<<money<<endl;
            cout<<"    35       。 "<<endl;
            cout<<"               。 "<<endl;
            money-=35;
        }
        if (d==3||d==4)
        {
            cout<<"  $"<<money<<endl;
            cout<<"    50       。 "<<endl;
            cout<<"               。 "<<endl;
            money-=50;
        }
        if (d==5)
        {
            cout<<"  $"<<money<<endl;
            cout<<"    60       。 "<<endl;
            cout<<"               。 "<<endl;
            money-=60;
        }
        cout<<"  $"<<money<<endl;
        while(money>0)
        {
            if (d==1||d==2||d==3) if(money>=10000)
                    if (d==4||d==5) if(money>=100000)
                        {
                            cout<<"    !"<<endl;
                            cout<<"   "<<t<<" 。"<<endl;
                            system("pause");
                            return 0;
                        }
            t++;
            cout<<"      ? "<<" "<<"  $"<<money<<endl;
            cin>>n;
            if(n==0)
            {
                borrow();
                tt=t+10;
            }
            if(t==tt) bool flag=pay();
            if(flag==false)
            {
                cout<<"         。"<<endl;
                cout<<"    !"<<endl;
                cout<<"    "<<t<<"  。"<<endl;
                system("pause");
                return 0;
            }
            if(n<0 || n>money)
            {
                cout<<"  "<<endl;
                cout<<"    !"<<endl;
                cout<<"    "<<t<<"  "<<endl;
                system("pause");
                return 0;
            }
            if (d=1) money=money+n*5;
            if (d=2) money=money+n*3;
            else money=money+n*2;
            if(money<0)
            {
                cout<<"    !"<<endl;
                cout<<"    "<<t<<"  "<<endl;
                system("pause");
                return 0;
            }
            for(int i=0; i<n; i++)
            {
                p=rand()%12000;
                if(p==0)
                {
                    int y;
                    y=rand()%4;
                    if(y==1)
                    {
                        cout<<"       !"<<endl;
                        if (d==5) money-=5000;
                        else money-=10000;
                    }
                }
                else if(p>=1&&p<=8)
                {
                    cout<<"        !"<<endl;
                    money-=1000;
                }
                else if(p>=15&&p<=50)
                {
                    cout<<"      !"<<endl;
                    money-=100;
                }
                else if(p>=61&&p<=360)
                {
                    cout<<"      !"<<endl;
                    money-=20;
                }
                else if(p>=401&&p<=1500)
                {
                    cout<<"      !"<<endl;
                    money-=5;
                }
            }
        }
    }
    if(money<=0)
    {
        cout<<"    。"<<endl;
        cout<<"    "<<t<<" 。"<<endl;
        system("pause");
        return 0;
    }
}

転載先:https://www.cnblogs.com/vercont/p/10210022.html