⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2746.cpp

📁 非常好的C++学习源码,里面包括各种算法的实现,二叉的的前中后序遍历等
💻 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 + -