返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     string n[5]={"子耕", "思惟", "璽安", "侑成", "挺桂"};
  8.     int x[3];
  9.     srand(time(NULL));
  10.     for(int i=0;i<3;i++)
  11.     {
  12.         x[i]=rand()%5;
  13.         for(int j=0;j<i;j++)
  14.         {
  15.             if(x[i]==x[j])
  16.             {
  17.                 i--;
  18.                 break;         
  19.             }        
  20.         }        
  21.     }
  22.     cout<<"掃廁所三位同學: ";
  23.     for(int i=0; i<3; i++)
  24.         cout<<n[x[i]]<<" ";
  25.     cout<<endl;
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼

TOP

返回列表