本帖最後由 陳妍蓁 於 2024-8-9 11:54 編輯
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- srand(time(NULL));
- string n[5]={" 子耕"," 思惟"," 璽安"," 侑成"," 挺桂"};
- int x[3];
- for(int i=0;i<3;i++){
- x[i]=rand()%5;
- for(int j=0;j<i;j++){
- if(x[i]==x[j]){
- i--;
- break;
- }
- }
- }
- cout<<"打掃的3位同學:";
- for(int i=0;i<3;i++)
- cout<<n[x[i]]<<endl;
- cout<<endl;
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |