📄 2746.cpp
字号:
#include<iostream>
using namespace std;
struct a
{
int p;
a *next;
};
int main()
{
a *link,*monkey,*mlast;
int n,m,count,i;
while (1)
{
cin>>n>>m;
if (n==0)
break;
link=NULL;
for (i=0;i<n;i++)
{
monkey=new a;
monkey->p=i+1;
if (link==NULL)
link=mlast=monkey;
else
{
mlast->next=monkey;
mlast=monkey;
}
}
mlast->next=link;
count=1;
if (m==1)
cout<<n<<endl;
else
{
while(link!=NULL)
{
if (link->next==link)
{
cout<<link->p<<endl;
delete link;
break;
}
if (count==m-1)
{
monkey=link->next;
link->next=monkey->next;
delete monkey;
count=0;
}
link=link->next;
count++;
}
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -