| ||||||||||
| 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 | |||||||||
尴尬了不知道错误在哪里,例子输出和特殊case的输出好像都对,大神帮忙看看代码import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = 0;
while (true) {
n = n + 1;
int p = scanner.nextInt();
int e = scanner.nextInt();
int i = scanner.nextInt();
int d = scanner.nextInt();
if (p == -1 && p == -1 && p == -1 && p == -1)
break;
int x = 0;
int pe = p - e;
int pi = p - i;
while (true) {
x = x + 1;
Float y = ((23 * (float) x + pe) / (float) 28);
Float z = ((23 * (float) x + pi) / (float) 33);
//23*x+p == 28*y+e == 33*z+i
//y与z同时是整数,说明3个高峰同天
if ((y.intValue() - y.floatValue()) == 0 && (z.intValue() - z.floatValue()) == 0)
break;
}
int result = 23 * x + p - d;
if(result>21252)result -= 21252;
System.out.println("Case " + n + ": the next triple peak occurs in " + result + " days.");
}
scanner.close();
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator