UVA 133


题目描述:点击打开链接


/*
	思路:初始化数组,根据输入的数值一步一步移动,
	移动到位后,将对应的数值做标记(改为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();
		}
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值