返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.    int a,b,c,p,n=1;
  9.    float t,t1=0,t2=0,t_sum=0;
  10.    string x[10];
  11.    int y[10];
  12.    system("cls");
  13.    cout<<"***超級金頭腦***"<<endl<<endl;
  14.    cout<<"遊戲規則: 電腦隨機出題,比賽誰能在最短的時間內算完3題!"<<endl<<endl;
  15.    system("pause");
  16.    re2:
  17.    system("cls");
  18.    cout<<"有幾位參賽者: ";
  19.    cin>>p;
  20.    if(p<1)
  21.    {
  22.        cout<<"輸入錯誤"<<endl;
  23.        _sleep(1500);
  24.        goto re2;
  25.    }
  26.    for(int i=1; i<=p; i++)
  27.    {
  28.    system("cls");
  29.    cout<<"第"<<n<<"位參賽者你好,請輸入你的大名: ";
  30.    cin>>x[n-1];
  31.    system("cls");
  32.    cout<<x[n-1]<<"同學請就位!"<<endl;
  33.    system("pause");
  34.    system("cls");
  35.    t2=0;
  36.    int q=0;
  37.    while(q!=3)
  38.    {
  39.     t1=clock();
  40.     a=rand()%899+101;
  41.     b=rand()%899+101;
  42.     cout<<a<<" + "<<b<<" = ";
  43.     cin>>c;
  44.     t2=clock()-t1;
  45.     if(c==a+b)
  46.    {
  47.        cout<<"答對了! 本題花了"<<t2<<"毫秒思考"<<endl;
  48.        q++;
  49.    }
  50.    else
  51.    {
  52.        cout<<"答錯了! 正確答案是"<<+a+b<<", 本題花了"<<t2<<"毫秒思考"<<endl;
  53.    }
  54.    t_sum+=t2;
  55.    }
  56.    y[n-1]=t_sum;
  57.    cout<<endl<<x[n-1]<<"同學總共花了"<<y[n-1]<<"毫秒!"<<endl<<endl;
  58.    n++;
  59.    t_sum=0;
  60.    system("pause");
  61.    }
  62.    system("cls");
  63.    for(int i=0; i<=(p-1); i++)
  64.    {
  65.        for(int j=0; j<=(p-1); j++)
  66.        {
  67.            int z;
  68.            string z1;
  69.            if(y[i]<y[j])
  70.            {
  71.                z=y[j];
  72.                y[j]=y[i];
  73.                y[i]=z;
  74.                z1=x[j];
  75.                x[j]=x[i];
  76.                x[i]=z1;
  77.            }
  78.        }
  79.    }
  80.    cout<<"***金頭腦風雲榜***"<<endl<<endl;
  81.    for(int i=0; i<=p-1; i++)
  82.    {
  83.        cout<<"第"<<i+1<<"名 "<<x[i]<<"\t"<<y[i]<<"毫秒"<<endl;
  84.    }
  85.    system("pause");
  86.    goto re;
  87.    return 0;
  88. }
複製代碼

TOP

返回列表