- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- srand(time(NULL));
- int n, a, b, ans;
-
- double start, end, pass;
- cout<<"*** 超級金頭腦 v1.0 ***"<<endl<<endl;
- cout<<"遊戲規則:電腦隨機出題,比賽誰能在最短時間內算對三題!"<<endl;
- system("pause");
- system("cls");
- cout<<"請問有幾位挑戰者?";
- cin>>n;
- string name[n];
- long 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)
- {
- 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;
- count++;
- }else
- {
- cout<<"答錯了!請從新作答"<<endl;
- }
- }
- }
- cout<<"*** 金頭腦風雲榜 ***"<<endl<<endl;
- string tmp1;
- long tmp2;
- for(int i=0; i<n-1; i++)
- {
- for(int j=i+1; j<n; j++)
- {
- if(sum[j]<sum[i])
- {
- tmp1=name[i];
- name[i]=name[j];
- name[j]=tmp1;
- tmp2=sum[i];
- sum[i]=sum[j];
- sum[j]=tmp2;
- }
- }
- }
- for(int i=0; i<n; i++)
- cout<<"第"<<i+1<<"名\t"<<name[i]<<"\t"<<sum[i]<<"毫秒"<<endl;
- cout<<endl;
- system("pause");
- system("cls");
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |