返回列表 發帖

[隨堂測驗] 賽馬程式 (三)

1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出





本帖隱藏的內容需要回復才可以瀏覽

本帖最後由 吳孟樵 於 2025-2-1 11:53 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int r=0,n=1,speed=50;
  6. re:
  7.     system("cls");
  8.     int s[4]= {0,0,0,0};
  9.     srand(time(NULL));
  10.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  11.     cout<<"------------------------------------------------------|終點"<<endl;
  12.     string p[4]= {"◆","★","▲","●"};
  13.     for(int i=0; i<=3; i++)
  14.     {
  15.         cout<<p[i]<<endl;
  16.     }
  17.     system("pause");
  18.     system("cls");
  19.     while(s[r]<=52)
  20.     {
  21.         r=rand()%4;
  22.         s[r]++;
  23.         cout<<"比賽進行中"<<endl;
  24.         cout<<"------------------------------------------------------|終點"<<endl;
  25.         for(int i=0; i<=3; i++)
  26.         {
  27.             for(int j=0; j<=s[i]; j++)
  28.             {
  29.                 cout<<" ";
  30.             }
  31.             cout<<p[i]<<endl;

  32.         }
  33.         _sleep(speed);
  34.         system("cls");
  35.     }
  36.     cout<<"比賽結束! 由"<<p[r]<<"先馳得點!"<<endl;
  37.     cout<<"------------------------------------------------------|終點"<<endl;
  38.     for(int i=0; i<=3; i++)
  39.     {
  40.         for(int j=0; j<=s[i]; j++)
  41.         {
  42.             cout<<" ";
  43.         }
  44.         cout<<p[i]<<endl;
  45.     }
  46.     system("pause");
  47.     n++;
  48.     goto re;
  49.     return 0;
  50. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int s[4]= {0,0,0,0};
  6.     string p[4]= {"1","2","3","4"};

  7.     srand(time(NULL));
  8.     cout<<"「好事成雙」賽馬場 第1局\n";
  9.     cout<<"------------------------|終點\n";
  10.     int r;
  11.     for(int i=0; i<4; i++)
  12.     {
  13.         cout<<p[i]<<endl;
  14.     }
  15.     system("pause");
  16.     system("cls");
  17.     while(s[r]<=18)
  18.     {
  19.         r=rand()%4;
  20.         s[r]++;
  21.         cout<<"比賽進行中\n";
  22.         cout<<"--------------------|\n";
  23.         for(int a=0; a<4; a++)
  24.         {
  25.             for(int j=0; j<s[a]; j++)
  26.             {
  27.                 cout<<" ";
  28.             }
  29.             cout<<p[a]<<endl;
  30.         }
  31.         _sleep(50);
  32.         system("cls");
  33.     }
  34.     cout<<"比賽結束由,"<<p[r]<<"先馳得點\n";
  35.     cout<<"-------------------\n";
  36.     for(int a=0; a<4; a++)
  37.     {
  38.         for(int j=0; j<s[a]; j++)
  39.         {
  40.             cout<<" ";
  41.         }
  42.         cout<<p[a]<<endl;

  43.     }

  44.     return 0;
  45. }
複製代碼

TOP

本帖最後由 黃品錡 於 2025-1-16 16:58 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n=0;
  6.     for(int a=0; a<5; a++)
  7.     {
  8.         n++;
  9.         system("cls");
  10.         int s[4]= {0,0,0,0};
  11.         int r;
  12.         int speed=1;
  13.         srand(time(NULL));
  14.         cout<<"「好事成雙」賽車場 第"<<n<<"局"<<endl;
  15.         cout<<"--------------------------------|終點"<<endl;
  16.         string p[4]= {"1","2","3","4"};
  17.         for(int i=0; i<=3; i++)
  18.         {
  19.             cout<<p[i]<<endl;
  20.         }
  21.         system("pause");
  22.         system("cls");
  23.         while(s[r]<=30)
  24.         {
  25.             r=rand()%4;
  26.             s[r]++;
  27.             cout<<"比賽進行中"<<endl;
  28.             cout<<"----------------------------------|終點"<<endl;
  29.             for(int i=0; i<=3; i++)
  30.             {
  31.                 for(int j=0; j<=s[i]; j++)
  32.                 {
  33.                     cout<<" ";
  34.                 }
  35.                 cout<<p[i]<<endl;

  36.             }
  37.             _sleep(speed);
  38.             system("cls");
  39.         }
  40.         cout<<"比賽結束! 由"<<p[r]<<"號先馳得點!"<<endl;
  41.         cout<<"----------------------------------|終點"<<endl;
  42.         for(int i=0; i<=3; i++)
  43.         {
  44.             for(int j=0; j<=s[i]; j++)
  45.             {
  46.                 cout<<" ";
  47.             }
  48.             cout<<p[i]<<endl;
  49.         }
  50.         system("pause");
  51.     }
  52.     system("pause");
  53.     return 0;
  54. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n=0;
  4. int main()
  5. {
  6.     re:
  7.     n++;
  8.     system("cls");
  9.     int s[4]= {0,0,0,0};
  10.     string p[4]= {"馬1","馬2","馬3","馬4"};
  11.     int r;
  12.     srand(time(NULL));
  13.     cout<<"[好事成雙]賽馬場 第"<<n<<"局"<<endl;
  14.     cout<<"-------------------------------------------------------------------------|終點"<<endl;
  15.     for(int i=0; i<4; i++)
  16.     {
  17.         cout<<p[i]<<endl;
  18.     }
  19.     system("pause");
  20.     system("cls");
  21.     while(s[r]<=74)
  22.     {
  23.         r=rand()%4;
  24.         s[r]++;
  25.         cout<<"比賽進行中"<<endl;
  26.         cout<<"-----------------------------------------------------------------------------|終點"<<endl;

  27.         for(int i=0; i<=3; i++)
  28.         {
  29.             for(int j=0; j<s[i]; j++)
  30.             {
  31.                 cout<<" ";
  32.             }
  33.             cout<<p[i]<<endl;

  34.         }
  35.         _sleep(50);
  36.         system("cls");
  37.     }
  38.     cout<<"比賽結束,由"<<p[r]<<"先馳得點!"<<endl;
  39.     cout<<"-------------------------------------------------------------------------|終點"<<endl;
  40.     for(int i=0; i<=3; i++)
  41.     {
  42.         for(int j=0; j<s[i]; j++)
  43.         {
  44.             cout<<" ";
  45.         }

  46.         cout<<p[i]<<endl;

  47.     }
  48.     goto re;
  49.     system("pause");
  50.     return 0;
  51. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n=0;
  4. int main()
  5. {
  6. re:
  7.     n++;
  8.     system("cls");
  9.     int s[]= {0,0,0,0};
  10.     string p[]= {"◆","★","▲","●"};
  11.     int r;
  12.     srand(time(NULL));
  13.     cout<<"「好事成雙」賽馬場"<<"第"<<n<<"局"<<endl;
  14.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  15.     for(int i=0; i<4; i++)
  16.     {
  17.         cout<<p[i]<<endl;
  18.     }
  19.     system("pause");
  20.     system("cls");
  21.     while(s[r]<=71)
  22.     {
  23.         r=rand()%4;
  24.         s[r]++;
  25.         cout<<"比賽進行中"<<endl;
  26.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  27.         for(int i=0; i<4; i++)
  28.         {
  29.             for(int j=0; j<s[i]; j++)
  30.             {
  31.                 cout<<" ";
  32.             }
  33.             cout<<p[i]<<endl;
  34.         }
  35.         _sleep(25);
  36.         system("cls");
  37.     }
  38.     cout<<"比賽結束,由"<<p[r]<<"先馳得點"<<endl;
  39.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  40.     for(int i=0; i<4; i++)
  41.     {
  42.         for(int j=0; j<s[i]; j++)
  43.             cout<<" ";
  44.         cout<<p[i]<<endl;
  45.     }
  46.     system("pause");
  47.     system("cls");
  48.     goto re;
  49.     return 0;
  50. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n=0;
  6.     for(int k=0; k<5; k++)
  7.     {
  8.         n++;
  9.         system("cls");
  10.         int s[4]= {0,0,0,0};
  11.         int r;
  12.         int speed=1;
  13.         srand(time(NULL));
  14.         cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  15.         cout<<"--------------------------------|終點"<<endl;
  16.         string p[4]= {"◆","★","▲","●"};
  17.         for(int i=0; i<=3; i++)
  18.         {
  19.             cout<<p[i]<<endl;
  20.         }
  21.         system("pause");
  22.         system("cls");
  23.         while(s[r]<=30)
  24.         {
  25.             r=rand()%4;
  26.             s[r]++;
  27.             cout<<"比賽進行中"<<endl;
  28.             cout<<"----------------------------------|終點"<<endl;
  29.             for(int i=0; i<=3; i++)
  30.             {
  31.                 for(int j=0; j<=s[i]; j++)
  32.                 {
  33.                     cout<<" ";
  34.                 }
  35.                 cout<<p[i]<<endl;

  36.             }
  37.             _sleep(speed);
  38.             system("cls");
  39.         }
  40.         cout<<"比賽結束! 由"<<p[r]<<"先馳得點!"<<endl;
  41.         cout<<"----------------------------------|終點"<<endl;
  42.         for(int i=0; i<=3; i++)
  43.         {
  44.             for(int j=0; j<=s[i]; j++)
  45.             {
  46.                 cout<<" ";
  47.             }
  48.             cout<<p[i]<<endl;
  49.         }
  50.         system("pause");
  51.     }
  52.     system("pause");
  53.     return 0;
  54. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n=0;
  6.     for(int a=0; a<5; a++)
  7.     {
  8.         n++;
  9.         system("cls");
  10.         int s[4]= {0,0,0,0};
  11.         int r;
  12.         int speed=1;
  13.         srand(time(NULL));
  14.         cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  15.         cout<<"--------------------------------|終點"<<endl;
  16.         string p[4]= {"◆","★","▲","●"};
  17.         for(int i=0; i<=3; i++)
  18.         {
  19.             cout<<p[i]<<endl;
  20.         }
  21.         system("pause");
  22.         system("cls");
  23.         while(s[r]<=30)
  24.         {
  25.             r=rand()%4;
  26.             s[r]++;
  27.             cout<<"比賽進行中"<<endl;
  28.             cout<<"----------------------------------|終點"<<endl;
  29.             for(int i=0; i<=3; i++)
  30.             {
  31.                 for(int j=0; j<=s[i]; j++)
  32.                 {
  33.                     cout<<" ";
  34.                 }
  35.                 cout<<p[i]<<endl;

  36.             }
  37.             _sleep(speed);
  38.             system("cls");
  39.         }
  40.         cout<<"比賽結束! 由"<<p[r]<<"先馳得點!"<<endl;
  41.         cout<<"----------------------------------|終點"<<endl;
  42.         for(int i=0; i<=3; i++)
  43.         {
  44.             for(int j=0; j<=s[i]; j++)
  45.             {
  46.                 cout<<" ";
  47.             }
  48.             cout<<p[i]<<endl;
  49.         }
  50.         system("pause");
  51.     }
  52.     system("pause");
  53.     return 0;
  54. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int ov;
  8.     re:
  9.     system("cls");
  10.     srand(time(NULL));
  11.     int s[]={0,0,0,0};
  12.     string p[]={"8","7","6","5"};
  13.     int r=0;
  14.     cout<<"「好事成雙」賽馬場  第 "<<ov<<" 局"<<"      歡迎各貴公司投資"<<endl;
  15.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  16.     for(int i=0; i<4; i++)
  17.         cout<<p[i]<<endl;
  18.     system("pause");
  19.     system("cls");
  20.     while(s[r]<=73)
  21.     {
  22.         r=rand()%4;   //0~3
  23.         s[r]++;
  24.         cout<<"比賽進行中"<<endl;
  25.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  26.         for(int i=0; i<4; i++)
  27.         {
  28.             for(int j=0; j<s[i]; j++)
  29.                 cout<<" ";
  30.             cout<<p[i]<<endl;
  31.         }
  32.         _sleep(50);
  33.         system("cls");
  34.     }
  35.     cout<<"比賽結束!  由 "<<p[r]<<" 先馳得點!"<<endl;
  36.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  37.     for(int i=0; i<4; i++)
  38.     {
  39.         for(int j=0; j<s[i]; j++)
  40.             cout<<" ";
  41.         cout<<p[i]<<endl;
  42.     }
  43.     system("pause");
  44.     ov++;
  45.     goto re;
  46.     return 0;
  47. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int z=0;
  4. int main()
  5. {
  6. re:
  7.     z++;
  8.     system("cls");
  9.     int s[]= {0,0,0,0};
  10.     string p[]= {"◆","★","▲","●"};
  11.     int r;
  12.     srand(time(NULL));
  13.     cout<<"「好事成雙」賽馬場"<<"第"<<z<<"局"<<endl;
  14.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  15.     for(int i=0; i<4; i++)
  16.     {
  17.         cout<<p[i]<<endl;
  18.     }
  19.     system("pause");
  20.     system("cls");
  21.     while(s[r]<=71)
  22.     {
  23.         r=rand()%4;
  24.         s[r]++;
  25.         cout<<"比賽進行中"<<endl;
  26.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  27.         for(int i=0; i<4; i++)
  28.         {
  29.             for(int j=0; j<s[i]; j++)
  30.             {
  31.                 cout<<" ";
  32.             }
  33.             cout<<p[i]<<endl;
  34.         }
  35.         _sleep(100);
  36.         system("cls");
  37.     }
  38.     cout<<"比賽結束,由"<<p[r]<<"先馳得點"<<endl;
  39.     cout<<"---------------------------------------------------------------| 終點"<<endl;
  40.     for(int i=0; i<4; i++)
  41.     {
  42.         for(int j=0; j<s[i]; j++)
  43.             cout<<" ";
  44.         cout<<p[i]<<endl;
  45.     }
  46.     system("pause");
  47.     system("cls");
  48.     goto re;
  49.     return 0;
  50. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n=0;
  4. int main()
  5. {
  6. re:
  7.     n++;
  8.     system("cls");
  9.     int s[]= {0,0,0,0};
  10.     string p[]= {"◆","★","▲","●"};
  11.     int r;
  12.     srand(time(NULL));
  13.     cout<<"「好事成雙」賽馬場"<<"第"<<n<<"局"<<endl;
  14.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  15.     for(int i=0; i<4; i++)
  16.     {
  17.         cout<<p[i]<<endl;
  18.     }
  19.     system("pause");
  20.     system("cls");
  21.     while(s[r]<=71)
  22.     {
  23.         r=rand()%4;
  24.         s[r]++;
  25.         cout<<"比賽進行中"<<endl;
  26.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  27.         for(int i=0; i<4; i++)
  28.         {
  29.             for(int j=0; j<s[i]; j++)
  30.             {
  31.                 cout<<" ";
  32.             }
  33.             cout<<p[i]<<endl;
  34.         }
  35.         _sleep(25);
  36.         system("cls");
  37.     }
  38.     cout<<"比賽結束,由"<<p[r]<<"先馳得點"<<endl;
  39.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  40.     for(int i=0; i<4; i++)
  41.     {
  42.         for(int j=0; j<s[i]; j++)
  43.             cout<<" ";
  44.         cout<<p[i]<<endl;
  45.     }
  46.     system("pause");
  47.     system("cls");
  48.     goto re;
  49.     return 0;
  50. }
複製代碼

TOP

  1. #include<bits\stdc++.h>
  2. #include<cstdlib>
  3. using namespace std;
  4. int n=1;
  5. int main()
  6. {
  7.     re:
  8.     system("cls");
  9.     int r;
  10.     srand(time(NULL));
  11.     int s[]={0,0,0,0};
  12.     string a[]={"★","◆","●","▲"};
  13.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  14.     cout<<"---------------| 終點"<<endl;
  15.     for(int i=0;i<4;i++)
  16.     {
  17.         cout<<a[i]<<endl;
  18.     }
  19.     system("pause");
  20.     system("cls");
  21.     while(s[r]<=15)
  22.     {
  23.         r=rand()%4;
  24.         s[r]++;
  25.         cout<<"比賽進行中"<<endl;
  26.         cout<<"---------------| 終點"<<endl;
  27.         for(int i=0;i<4;i++)
  28.         {
  29.             for(int j=0;j<s[i];j++)
  30.                 cout<<" ";
  31.             cout<<a[i]<<endl;
  32.         }
  33.         _sleep(50);
  34.         system("cls");
  35.     }
  36.     system("cls");
  37.     cout<<"比賽結束"<<endl;
  38.     cout<<"---------------| 終點 由 "<<a[r]<<" 先馳得點!"<<endl;
  39.     for(int i=0;i<4;i++)
  40.         {
  41.             for(int j=0;j<s[i];j++)
  42.                 cout<<" ";
  43.             cout<<a[i]<<endl;
  44.         }
  45.     system("pause");
  46.     n++;
  47.     goto re;
  48.     return 0;
  49. }
複製代碼

TOP

返回列表