本帖最後由 劉奕劭 於 2024-8-17 15:52 編輯
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- #include<cmath>
- using namespace std;
- int main()
- {
- float a,b,c,people,d,tmp;
- string name[9999];
- srand(time(NULL));
- int e=1,x=1;
- int right=3;
- int n[2],o[9999],p[9999];
- cout<<"**超級金頭腦**"<<endl;
- cout<<"遊戲規則:由電腦出題,看誰能在最短時間內連續答對三題"<<endl;
- cout<<"有幾位挑戰者:";
- cin>>people;
- for(int j=1; j<=people; j++){
- cout<<"第"<<e<<"位挑戰者的大名:";
- cin>>name[j-1];
- cout<<name[j-1]<<"同學請就位!!";
- for(int k=1; k<=right; k++){
- for(int i=0; i<2; i++)
- {
- n[i]=rand()%49+51;
- }
- cout<<n[0]<<"+"<<n[1]<<"=?";
- cin>>a;
- b=clock()-c;
- if(a==n[0]+n[1]){
- cout<<"答對了! 本題花了"<<b<<"毫秒思考"<<endl;
- }else
- {
- cout<<"答錯了! 本題花了"<<b<<"毫秒思考"<<endl;
- right++;
- }
- c=clock();
- d=b+d;
- }
- o[j-1]=d;
- e++;
- }for(int l=0; l<9999; l++)
- {
- for(int m=l+1; m<people; m++)
- {
- if(o[m]<o[l])
- {
- tmp=o[m];
- o[m]=o[l];
- o[l]=tmp;
- }
- }
- }
- system("pause");
- cout<<"***風雲榜***"<<endl;
- for(int i=0; i<=9; i++)
- {
- cout<<"第"<<x<<"名 ";
- cout<<name[i]<<" ";
- cout<<o[i]<<"毫秒"<<endl;
- x++;
- }
- system("pause");
- return 0;
- }
複製代碼 |