POJ 1006

来源:互联网 发布:京东 省市区数据库 编辑:程序博客网 时间:2024/05/29 17:53

这道题难度在于数学通式的转换,如果不理解中国剩余定理,这道题做出来感觉也比较水,代码如下:

import java.util.Scanner;public class poj1006 {/** * @param args */public static void main(String[] args) {Scanner in = new Scanner(System.in);int loop = 1;while (true) {int p = in.nextInt();int e = in.nextInt();int i = in.nextInt();int d = in.nextInt();if (p == -1 && e == -1 && i == -1 && d == -1) {break;}int days = (5544 * p + 14421 * e + 1288 * i - d + 21252) % 21252;if (days <= 0) {System.out.println("Case " + loop+ ": the next triple peak occurs in " + (21252 - days)+ " days.");} else {System.out.println("Case " + loop+ ": the next triple peak occurs in " + days+ " days.");}loop++;}}}


0 0
原创粉丝点击