您的位置:首页 > 其它

报数问题 (数组实现)

2009-06-17 11:14 239 查看
#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
请按任意键继续. . .
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: