n代表总数,编号1~n,m代表从第几个开始数,k代表数几个就去掉
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node
{
int num;
node *next;
node *per;
};
void creat(node *head ,int n)
{
node *cur;
cur = head;
for(int i = 2 ;i <= n ; i ++ )
{
node *temp = new node();
temp -> num = i;
cur -> next = temp;
temp -> per = cur;
cur = temp;
}
cur -> next =head;
head -> per = cur;
}
void john(node *head , int m ,int n ,int k)
{
int num = 1;
node *cur = head;
for(int i = 1 ; i < m ; i ++ )
{
cur = cur -> next ;
}
int sum = 0;
for(int i = 0 ; ; i ++ )
{
if(num == k)
{
cout <<cur -> num <<endl ;
cur -> per -> next = cur -> next;
cur -> next -> per = cur -> per;
sum ++ ;
if(sum == n-1)
{
cur = cur-> next;
break;
}
num = 0;
}
cur = cur -> next ;
num ++ ;
}
cout << cur->num <<endl;
}
int main()
{
int n , m , k ;
while(cin >> n >> m >> k)
{
node *head;
head = new node();
head->num = 1;
creat(head , n);
john(head , m , n ,k);
}
}