题解-队列 | #围圈报数#

围圈报数

https://www.nowcoder.com/practice/b033062d346c4e42a7191b94164c1cd7

#include <iostream>
#include <queue>
using namespace std;
queue<int> q;

int main(){
    int m;
    cin >> m;
    while(m--){
        int n, cnt = 0;
        cin >> n;
        for(int i = 1; i <= n; i ++) q.push(i);
        while(q.size()){
            int t = q.front();
            q.pop();
            cnt ++;
            if(cnt != 3) q.push(t);
            else{
                cout << t << ' ';
                cnt = 0;
            } 
        }
        cout << endl;
    }

    return 0;
}

全部评论

相关推荐

2025-12-31 18:42
复旦大学 Java
点赞 评论 收藏
分享
孙艹肘:校招不给三方直接让实习我都去了,,主打一个在学校呆着也是闲着,不如出来实习一下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务