为了账号安全,请及时绑定邮箱和手机立即绑定

C++的编程!求助!

C++的编程!求助!

C++
慕粉4825583 2018-01-01 09:47:16
有n个人围成一圈,顺序排号。从第1个学生开始报数(从1到3报数),凡报到3的学生退出圈子,到最后留下一名学生,问最后留下的是原来排在第几号。
查看完整描述

2 回答

?
coreIdeaLJJ

TA贡献2条经验 获得超0个赞


我要考一下

查看完整回答
反对 回复 2018-01-01
?
Camel97

TA贡献49条经验 获得超38个赞

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if(n < 1)
    {
        cout << "Please verify the number of students is larger than zero !" << endl;
        return 0;
    }
    else if(1 == n || 2 == n)
    {
        cout << "The No." << n << " student is left at last. "<<endl;
        return 0;
    }
    int array[n];
    for(int i = 0 ; i < n; i++)
        array[i] = i+1;
    int index = 2;
    int cont = 0;
    while(cont < n-1)
    {
        array[index] = 0;
        cont++;
        for(int j = 0 ; j < 3; j++)
        {
            index++;
            if(index >= n) index = index-n;
            while(0 == array[index])
            {
                index++;
                if(index >= n) index = index-n;
            }
        }
    }
    for(int i = 0 ; i < n ; i++)
    {
        if(0 != array[i])
            cout << "The No." << array[i] << " student is left at last. " <<endl;
    }
    return 0;
}


查看完整回答
反对 回复 2018-01-01
?
qq_缘定三生石

TA贡献15条经验 获得超5个赞

这应该是一个环的问题,我不会(ΘˍΘ=)???

查看完整回答
反对 回复 2018-01-01
  • 2 回答
  • 0 关注
  • 1733 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信