- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int n;
-
- cout<<"*** 超級金頭腦 v1.0 ***"<<endl;
- cout<<endl;
- cout<<"遊戲規則: 電腦隨機出題,比賽誰能在最短時間內算對三題!"<<endl;
- system("pause");
- system("cls");
- cout<<"有幾位挑戰者? ";
- cin>>n;
- string name[n];
- double sum[n];
-
- system("cls");
- for(int i=0;i<n;i++) /
- {
- cout<<"第"<<i+1<<"位挑戰者您好,請輸入您的大名:";
- cin>>name[i];
- system("pause");
- system("cls");
- cout<<name[i]<<"同學請就位!"<<endl;
- system("pause");
- system("cls");
-
- int count=0;
- while(count<3)
- {
- int a,b,ans;
- double start,end,pass;
- a = rand()%889+111;
- b = rand()%889+111;
- cout<<a<<" + "<<b <<" = ";
- start = clock();
- cin>>ans;
- end = clock();
- pass = end-start;
- if(ans == (a+b))
- {
- cout<<"答對了!本題你花了"<<pass<<"毫秒思考!"<<endl;
- sum[i] += pass;
- count++;
- }else
- {
- cout<<"答錯了!經過"<<pass<<"毫秒!"<<endl;
- sum[i] += pass;
- }
- }
- cout<<name[i]<<"同學總共花了"<<sum[i]<<"毫秒!"<<endl;
- system("pause");
- system("cls");
- }
-
-
- double tmp;
- string tmp2;
- cout<<"*** 金頭腦風雲榜 ***"<<endl<<endl;
- for(int i=0; i<n-1; i++)
- {
- for(int j=i+1; j<n; j++)
- {
- if(sum[j]<sum[i])
- {
- tmp=sum[i];
- sum[i]=sum[j];
- sum[j]=tmp;
- tmp2=name[i];
- name[i]=name[j];
- name[j]=tmp2;
- }
- }
- }
- for(int i=0; i<n; i++)
- cout<<"第 "<<i+1<<"名\t"<<name[i]<<"\t"<<sum[i]<<"毫秒"<<endl;
- cout<<endl;
-
- system("pause");
- return 0;
- }
複製代碼 |