TCHS-12-250

 

Problem Statement

     In some of the old historical chronicles the Indict system of chronology was used. Instead of a year, this system uses three integers, called indict, circle to the Sun, and circle to the Moon. Let's denote them as indict, circleSun, circleMoon.

 

Each of these three integers has a unique range. indict is between 1 and 15, circleSun is between 1 and 28, and circleMoon is between 1 and 19 (all ranges are inclusive). Initially, at year 1, all three of these numbers are equal to 1. Every year, all three numbers increase by 1, and whenever a number exceeds its upper bound (15, 28, and 19, respectively), it is reset to 1. For example, in year 16, indict = 1, circleSun = 16, and circleMoon = 16.

 

Given the ints indict, circleSun, and circleMoon, return the earliest year that the three numbers can represent. Time starts at year 1, so the return value will never be less than 1.

Definition

    
Class: IndictDates
Method: getYear
Parameters: int, int, int
Returns: int
Method signature: int getYear(int indict, int circleSun, int circleMoon)
(be sure your method is public)
    
 

Constraints

- indict will be between 1 and 15, inclusive.
- circleSun will be between 1 and 28, inclusive.
- circleMoon will be between 1 and 19, inclusive.

Examples

0)  
    
1

16

16

Returns: 16

This is the example from the problem statement.
1)  
    
1

1

1

Returns: 1

Initially we are at year 1.
2)  
    
1

2

3

Returns: 5266

 
3)  
    
15

28

19

Returns: 7980

 
public class IndictDates {

	public int getYear(int in, int cs, int cm) {
		int i = 1, j = 1, k = 1, sum = 1;
		while (!(i == in && j == cs && k == cm)) {
			i = i % 15 + 1;
			j = j % 28 + 1;
			k = k % 19 + 1;
			sum++;
		}
		return sum;
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值