AC了然后写了个链表,求调!
查看原帖
AC了然后写了个链表,求调!
828573
CurryNo_1楼主2022/12/24 00:46
#include<iostream>
#include<list>
using namespace std;
int n,m,cnt=0;
int main()
{
	cin >> n >> m;
	list<int>l;
	for(int i=1;i<=n;i++) l.push_back(i);
	list<int>::iterator it=l.begin();
	while(!l.empty())
	{
		cnt++;
		if(it==l.end())  it=l.begin();
		if(cnt==m)
		{
			cout << *it << " ";
			l.erase(it);//出圈 
			cnt=0;
		}
		it++;
	} 
}

样例答案输出3、3,还是需要两个迭代器?

2022/12/24 00:46
加载中...