WUST Online Judge - 2103: 生理周期

2103: 生理周期

Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lld
Submitted: 315  Accepted: 99
[Submit][Status][Web Board]

Description

人有体力、情商、智商的高峰日子,它们分别每隔23 天、28 天和 33 天出现一次。 

对于每个人,我们想知道何时三个高峰落在同一天。 

给定三个高峰出现的日子p,e和i(不一定是第一次高峰出现的日子),再给定另一个指定的日子d,你的任务是输出日子d之后,下一次三个高峰落在同一天的日子(用距离d的天数表示 )。

例如:给定日子为10,下次出现三个高峰同一天的日子是12,则输出2。

Input

多组测试数据,每组测试数据在一行中输入四个整数:p,e,i和d。p,e,i分别表示体力、情感和智商高峰出现的日子。d是给定的日子,可能小于p,e 或i。所有给定日子是非负的并且小于或等365,所求的日子小于或等于21252。

Output

每组测试数据的输出占一行(具体格式Sample Output )。

Case #n: the next triple peak occurs in s days.

其中n为传输数据组数,从1开始计数。s表示从给定日子起下一次三个高峰同一天的日子(距离给定日子的天数)。

Sample Input

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40

Sample Output

Case #1: the next triple peak occurs in 21252 days.
Case #2: the next triple peak occurs in 21152 days.
Case #3: the next triple peak occurs in 19575 days.
Case #4: the next triple peak occurs in 16994 days.
Case #5: the next triple peak occurs in 8910 days.
Case #6: the next triple peak occurs in 10789 days.

代码如下:

#include <stdio.h>

int main() {
    int i, P, E, I, D, flag = 0;
    while (scanf("%d%d%d%d", &P, &E, &I, &D) != EOF) {
        flag++;
        P %= 23; E %= 28; I %= 33;
        for (i = I; ; i += 33) {
            if ((i - E) % 28 == 0 && (i - P) % 23 == 0 && (i - I) % 33 == 0 && i > D)
                break;
        }
        printf("Case #%d: the next triple peak occurs in %d days.\n", flag, i - D);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mcr-tcp/p/9170575.html
今日推荐