用数组表示

1 #include<iostream>
2
3 using namespace std;
4
5 int main(){
6 int a[30];
7 bool visited[30];
8 for(int i=0; i<30; i++){
9 cout<<i+1<<" ";
10 a[i] = i;
11 visited[i] = false;
12 }
13 cout<<endl;
14
15 // 每个人数的数
16 int step = 0;
17 // 用来执行大循环
18 int cir = 0;
19 // 计算出局的人数
20 int total = 0;
21
22 while(total < 30){
23 if(visited[cir] == false){
24 step = (step + 1)%7;
25 if(step == 0){
26 visited[cir] = true;
27 total++;
28 cout<<cir+1<<" ";
29 }
30 }
31 cir = (cir+1)%30;
32
33 }
34 }
