返回列表 發帖
  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.   }
  23.   cout<<"掃廁所三位同學: ";
  24.   for(int i=0;i<3;i++)
  25.   {
  26.     cout<<n[x[i]]<<" ";
  27.          
  28.   }  
  29.    
  30. system("pause");
  31. return 0;
  32. }   
複製代碼

TOP

返回列表