返回列表 發帖
本帖最後由 劉奕劭 於 2024-8-17 15:52 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. #include<cmath>
  5. using namespace std;
  6. int main()
  7. {
  8.     float a,b,c,people,d,tmp;
  9.     string name[9999];
  10.     srand(time(NULL));
  11.     int e=1,x=1;
  12.     int right=3;
  13.     int n[2],o[9999],p[9999];
  14.     cout<<"**超級金頭腦**"<<endl;
  15.     cout<<"遊戲規則:由電腦出題,看誰能在最短時間內連續答對三題"<<endl;
  16.     cout<<"有幾位挑戰者:";
  17.     cin>>people;
  18.     for(int j=1; j<=people; j++){

  19.             cout<<"第"<<e<<"位挑戰者的大名:";
  20.             cin>>name[j-1];
  21.             cout<<name[j-1]<<"同學請就位!!";
  22.             for(int k=1; k<=right; k++){
  23.                 for(int i=0; i<2; i++)
  24.                     {
  25.                         n[i]=rand()%49+51;

  26.                     }
  27.             cout<<n[0]<<"+"<<n[1]<<"=?";
  28.             cin>>a;
  29.             b=clock()-c;
  30.             if(a==n[0]+n[1]){

  31.                 cout<<"答對了! 本題花了"<<b<<"毫秒思考"<<endl;
  32.             }else
  33.             {
  34.                 cout<<"答錯了! 本題花了"<<b<<"毫秒思考"<<endl;
  35.                 right++;
  36.             }
  37.             c=clock();
  38.             d=b+d;

  39.             }
  40.     o[j-1]=d;
  41.     e++;

  42.     }for(int l=0; l<9999; l++)
  43.     {
  44.     for(int m=l+1; m<people; m++)
  45.          {
  46.              if(o[m]<o[l])
  47.              {
  48.                  tmp=o[m];
  49.                  o[m]=o[l];
  50.                  o[l]=tmp;
  51.              }
  52.          }
  53.     }
  54.     system("pause");
  55.     cout<<"***風雲榜***"<<endl;
  56.     for(int i=0; i<=9; i++)
  57.     {

  58.         cout<<"第"<<x<<"名   ";
  59.         cout<<name[i]<<"   ";
  60.         cout<<o[i]<<"毫秒"<<endl;
  61.         x++;
  62.     }
  63.     system("pause");
  64.     return 0;
  65. }
複製代碼

TOP

返回列表