#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
Node *next;
int data;
}Node,*LNode;
int main()
{
int n,m;
cin>>m>>n;
LNode head,tail,p,temp;
head=new Node;
head->next=NULL;
tail=head;
for(int i=1;i<=m;i++)
{
p=new Node;
p->next=NULL;
p->data=i;
tail->next=p;
tail=p;
}
p=head;
tail->next=head->next;
int k=n;
while(p)
{
if(k==1&&m)
{
m--;
cout<<p->next->data<<' ';
temp=p->next;
p->next=temp->next;
free(temp);
k=n;
}
k-=1;
p=p->next;
}
return 0;
}
因为算法我学的很一般所以我就用链表写的,但是!我发现我这个代码过不了10 1的样例,跪求各位佬分享可以过10 1的代码,亚比囧囧囧