| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
附上我的程序,希望大家抽空帮忙看看In Reply To:刚刚想到,数据123 128 133 1的正确结果是不是99? Posted by:ahy at 2004-11-19 15:36:37 //Problem 1006
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
int pT = 23, eT = 28, iT = 33;
int eiT = 28 * 33;
int caseNum = 1;
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(stdin.readLine());
int p = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
int i = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
while(p!=-1 && e!=-1 && i!=-1 && d!=-1) {
if(p==0 || e==0 || i==0) {
System.out.println("Case " + (caseNum++) + ": the next triple peak occurs in " + (21252-d) + " days.");
}else {
int delta;
if(i!=e) {
delta = i - e;
for(; delta%eT!=0 || delta<0; delta+=iT); //寻找e与i高峰同时出现的日期距给定e的日数
}else delta = 0;
if(delta+e!=p) {
delta += e - p;
for(; delta%pT!=0 || delta<0; delta+=eiT); //寻找三峰同时出现的日期距给定p的日数
}
int nextTriPeak = p + delta - d; //此处找到的三峰日数是给定的p,e,i往后的日数
if(nextTriPeak<=0) nextTriPeak += 21252; //若三峰出现在d之前(含d当日)、p,e,i之后,则要加上21252
else if(nextTriPeak>21252) nextTriPeak -= 21252; //若三峰出现在d之后、p,e,i之前,则要减去21252
System.out.println("Case " + (caseNum++) + ": the next triple peak occurs in " + nextTriPeak + " days.");
}
st = new StringTokenizer(stdin.readLine());
p = Integer.parseInt(st.nextToken());
e = Integer.parseInt(st.nextToken());
i = Integer.parseInt(st.nextToken());
d = Integer.parseInt(st.nextToken());
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator