- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- re:
- int a,b,c,p,n=1;
- float t,t1=0,t2=0,t_sum=0;
- string x[10];
- int y[10];
- system("cls");
- cout<<"***超級金頭腦***"<<endl<<endl;
- cout<<"遊戲規則: 電腦隨機出題,比賽誰能在最短的時間內算完3題!"<<endl<<endl;
- system("pause");
- re2:
- system("cls");
- cout<<"有幾位參賽者: ";
- cin>>p;
- if(p<1)
- {
- cout<<"輸入錯誤"<<endl;
- _sleep(1500);
- goto re2;
- }
- for(int i=1; i<=p; i++)
- {
- system("cls");
- cout<<"第"<<n<<"位參賽者你好,請輸入你的大名: ";
- cin>>x[n-1];
- system("cls");
- cout<<x[n-1]<<"同學請就位!"<<endl;
- system("pause");
- system("cls");
- t2=0;
- int q=0;
- while(q!=3)
- {
- t1=clock();
- a=rand()%899+101;
- b=rand()%899+101;
- cout<<a<<" + "<<b<<" = ";
- cin>>c;
- t2=clock()-t1;
- if(c==a+b)
- {
- cout<<"答對了! 本題花了"<<t2<<"毫秒思考"<<endl;
- q++;
- }
- else
- {
- cout<<"答錯了! 正確答案是"<<+a+b<<", 本題花了"<<t2<<"毫秒思考"<<endl;
- }
- t_sum+=t2;
- }
- y[n-1]=t_sum;
- cout<<endl<<x[n-1]<<"同學總共花了"<<y[n-1]<<"毫秒!"<<endl<<endl;
- n++;
- t_sum=0;
- system("pause");
- }
- system("cls");
- for(int i=0; i<=(p-1); i++)
- {
- for(int j=0; j<=(p-1); j++)
- {
- int z;
- string z1;
- if(y[i]<y[j])
- {
- z=y[j];
- y[j]=y[i];
- y[i]=z;
- z1=x[j];
- x[j]=x[i];
- x[i]=z1;
- }
- }
- }
- cout<<"***金頭腦風雲榜***"<<endl<<endl;
- for(int i=0; i<=p-1; i++)
- {
- cout<<"第"<<i+1<<"名 "<<x[i]<<"\t"<<y[i]<<"毫秒"<<endl;
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |