现在的位置: 首页 > 综合 > 正文

poj 1006

2014年08月07日 ⁄ 综合 ⁄ 共 634字 ⁄ 字号 评论关闭

中国剩余定理

#include<iostream>
using namespace std;
int main()
{
		int ncase = 0;
		int p,e,i,d;
        while (true) {
			ncase++;
			cin>>p>>e>>i>>d;
			if (p == -1)
				return 0;
			int ans = (5544 * p + 14421 * e + 1288 * i-d+21252) % 21252;
			if(ans==0)
				ans=21252;
			cout<<"Case "<<ncase<<": the next triple peak occurs in "<<ans<<" days."<<endl;
		}
        return 0;
}

import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int ncase = 0;
		while (true) {
			ncase++;
			int p = in.nextInt();
			int e = in.nextInt();
			int i = in.nextInt();
			int d = in.nextInt();
			if (p == -1)
				return;
			int ans = (5544 * p + 14421 * e + 1288 * i-d+21252) % 21252;
			if(ans==0)
				ans=21252;
			System.out.println("Case " + ncase + ": the next triple peak occurs in " + ans + " days.");
		}
	}
}

抱歉!评论已关闭.