#include "iostream"
#include "cstdlib"
using namespace std;
int main(int argc, char* argv[])
{
int Array[50];
const int ArrayLength = sizeof(Array)/sizeof(Array[0]);
for(int i=0;i<ArrayLength;i++)
{
Array[i] = i+1 ;
}
int Count = 0 ;
int biaoji=1 ;
int per = 0 ;
cout<<"Sequence that persons leave the circle:/n" ;
while(Count!=ArrayLength)
{
if(biaoji%3==0 && Array[per]!=0)
{
cout<<Array[per]<<"/t";
Array[per]=0;
biaoji=1;
Count++;
if (Count==ArrayLength-1) cout<<"/nThe Last one is:/n";
}
else
{
if(Array[per]!=0) biaoji++;
per++;
if(per>=ArrayLength) per%=ArrayLength ;
}
}
cout<<endl;
system("pause");
return 0;
}
结果为:
Sequence that persons leave the circle:
3 6 9 12 15 18 21 24 27 30
33 36 39 42 45 48 1 5 10 14
19 23 28 32 37 41 46 50 7 13
20 26 34 40 47 4 16 25 35 44
8 22 38 2 29 49 31 17 43
The Last one is:
11
请按任意键继续. . .