#include <stdio.h>#include <stdlib.h>#include <string.h>#define LOCAL#define MAXN 30typedefstructnode{
intdata;
structnode*pre, *next;
}*Node;
Nodelink[MAXN] ;
voidinit(intn, Node*head, Node*rear);
intmain()
{
intn, k, m;
Nodehead, rear;
intcount1, count2;
Nodep, q, r, s;
intfirst;
head= (Node)malloc(sizeof(structnode));
rear= (Node)malloc(sizeof(structnode));
#ifdef LOCALfreopen("c://uva_in.txt", "r", stdin);
#endifwhile (scanf("%d%d%d", &n, &k, &m) ==3&&!(n==0&&k==0&&m==0))
{
init(n, &head, &rear);
p=head;
q=rear;
first=1;
count1=count2=1;
while(n>0)
{
while (count1<k)
{
p=p->next;
count1++;
}
while (count2<m)
{
q=q->pre;
count2++;
}
if (p!=q)
{
if (first)
first=0;
elseprintf(",");
printf("%3d%3d", p->data, q->data);
if (n>2)
{
if (p->next!=q)
{
p->pre->next=p->next;
p->next->pre=p->pre;
r=p;
p=p->next;
free(r);
q->pre->next=q->next;
q->next->pre=q->pre;
r=q;
q=q->pre;
free(r);
} else {
p->pre->next=q->next;
q->next->pre=p->pre;
r=p;
s=q;
p=q->next;
q=r->pre;
free(r);
free(s);
}
} elseif (n==2)
{
free(p);
free(q);
}
n-=2;
}else {
if (first)
first=0;
elseprintf(",");
printf("%3d", p->data);
if (n>1)
{
p->pre->next=p->next;
p->next->pre=p->pre;
r=p;
p=p->next;
q=q->pre;
free(r);
} elseif (n==1)
{
free(p);
}
n-=1;
}
count1=count2=1;
}
printf("/n");
}
return0;
}
voidinit(intn, Node*head, Node*rear)
{
inti;
Nodep, q;
for (i=0; i<n; i++)
{
p= (Node)malloc(sizeof(structnode));
p->data=i+1;
if (i==0)
{
*head=p;
p->next=NULL;
q=p;
} else {
p->pre=q;
p->next=NULL;
q->next=p;
q=p;
}
if (i==n-1)
*rear=q;
}
(*head)->pre=*rear;
(*rear)->next=*head;
}