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 |
我的程序哪里考虑错了?总的想法就是每输入一个时间,计算一下驾驶的公里数,下一个输入的如果不是速度,就输出公里数。例子给的数据还是能够符合的,但提交就wa了,肯定是哪里有问题。自己查自己的错总是不太容易,谁帮忙看一下,谢谢。 import java.util.Scanner; public class Main{ public static void main(String[] args){ int speed = 0; long dist = 0; boolean needOutput = false; long lastTime = 0; long nowTime = 0; String s = null; String sPre = null; Scanner cin = new Scanner(System.in); while(cin.hasNext()){ s = cin.next(); if(s.contains(":")){ String[] time = s.split(":"); nowTime = Integer.parseInt(time[0])*3600+ Integer.parseInt(time[1])*60+ Integer.parseInt(time[2]); if(needOutput){ System.out.println(sPre+" "+Math.round(dist/3600.0)+" km"); } dist = dist + (nowTime - lastTime) * speed; lastTime = nowTime; needOutput = true; sPre = s; } else{ speed = Integer.parseInt(s); needOutput = false; } } if(needOutput){ System.out.println(s+" "+Math.round(dist/3600.0)+" km"); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator