题解 | #围圈报数#

围圈报数

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

#include <iostream>
#include <list>
using namespace std;


 
int main(){
	int m,n,tmp;
	cin>>m;
	while(m--){
		list<int> l;
		cin>>n;
		for(int i = 1; i <= n; i++)
			l.push_back(i);
		
		while(!l.empty()){
			for(int cnt = 2; cnt > 0 && l.size() > 1; cnt--){
				tmp = l.front();
				l.pop_front();	
				l.push_back(tmp);
			}
			cout<<l.front()<<" ";
			l.pop_front();
		}
        cout<<endl;
	}

}

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 评论 收藏
转发
2 收藏 评论
分享
牛客网
牛客企业服务