基本上完全借鉴了rujia的代码。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,k,m,a[25];
int go(int p,int cnt,int q)
{
while(cnt--)
{
do
{
p=(p+n+q-1)%n+1;
}while(a[p]==0);
}
return p;
}
int main()
{
while(cin>>n>>k>>m&&n)
{
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
a[i]=i;
int left=n,p1=n,p2=1;
while(left)
{
p1=go(p1,k,1);
p2=go(p2,m,-1);
printf("%3d",p1);
left--;
if(p1!=p2)
{
printf("%3d",p2);
left--;
}
a[p1]=a[p2]=0;
if(left) printf(",");
}
cout<<endl;
}
}