原题目 http://acm.pku.edu.cn/JudgeOnline/problem?id=1006
我写的java代码如下:
import java.util.*;
public class Acm1006 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = 0;
int j = 1;
while(true)
{
int p = in.nextInt() , e = in.nextInt(),i = in.nextInt(),d = in.nextInt();
if( p == -1 && e == -1 && i == -1 && d == -1 )
break;
n = ( p * 5544 + e * 14421 + i * 1288 - d + 21252 ) % 21252;
if( n <=0 )
n = 21252;
System.out.println( "Case " + (j++) + ": the next triple peak occurs in " + n + " days. ");
}
}
}
同样的逻辑我用C++写了一遍一次就AC了,但是用java提示Time Limit Exceed
说明时间超限了,那位高手指点一二啊,小弟不盛感激...
------解决方案--------------------
这是由于其采用测试数据中的最后一行“-1 -1 -1 -1”后缺少了个换行符,导致程序未完全终止。