返回列表 發帖
  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.     {
  25.             cout<<n[x[i]]<<" ";
  26.     }
  27.     cout<<endl;
  28.     system("pause");
  29.     return 0;
  30. }
複製代碼

TOP

返回列表