报数问题 (数组实现)

 

#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
请按任意键继续. . .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值