题目描述:点击打开链接
/*
思路:初始化数组,根据输入的数值一步一步移动,
移动到位后,将对应的数值做标记(改为0),假若遇到标记,
便不计数,跳过这个标记继续移动. 依次类推.
*/
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
int T=cin.nextInt();
int n=cin.nextInt();
int m=cin.nextInt();
if(T==0 && n==0 && m==0)break;
int num[]=new int[T];
for(int i=0;i<T;++i)
num[i]=i+1;
int a=-1,b=0;
int count=T;
while(count!=0)
{
int cnt=0;
while(cnt!=n)
{
a=(a+1)%T;
if(num[a]==0)continue;
cnt++;
}
cnt=0;
while(cnt!=m)
{
if(--b<0)b=T-1;
if(num[b]==0)continue;
cnt++;
}
if(num[a]==num[b])
{
if(count==1)
System.out.printf("%3d",num[a]);
else
System.out.printf("%3d,",num[a]);
num[a]=0;
count-=1;
}
else
{
if(count==2)
System.out.printf("%3d%3d",num[a],num[b]);
else
System.out.printf("%3d%3d,",num[a],num[b]);
num[a]=num[b]=0;
count-=2;
}
}
System.out.println();
}
}
}