2013
11-11

# Average Speed

You have bought a car in order to drive from Waterloo to a big city. The odometer on their car is broken, so you cannot measure distance. But the speedometer and cruise control both work, so the car can maintain a constant speed which can be adjusted from time to time in response to speed limits, traffic jams, and border queues. You have a stopwatch and note the elapsed time every time the speed changes. From time to time you wonder, “how far have I come?”. To solve this problem you must write a program to run on your laptop computer in the passenger seat.

Standard input contains several lines of input: Each speed change is indicated by a line specifying the elapsed time since the beginning of the trip (hh:mm:ss), followed by the new speed in km/h. Each query is indicated by a line containing the elapsed time. At the outset of the trip the car is stationary. Elapsed times are given in non-decreasing order and there is at most one speed change at any given time.

For each query in standard input, you should print a line giving the time and the distance travelled, in the format below.

00:00:01 100
00:15:01
00:30:01
01:00:01 50
03:00:01
03:00:05 140


00:15:01 25.00 km
00:30:01 50.00 km
03:00:01 200.00 km


//* @author
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;

public class Main
{
static int hh;
static int mm;
static int ss;
static double sumDist;
static double speed;
public static void main(String[] args) throws Exception
{
}

{
StringTokenizer st = null;
String stemp = null;
{
st = new StringTokenizer(stemp," ");
if(st.countTokens()==2)
{
stemp = st.nextToken();
double tempspeed = Double.valueOf(st.nextToken()) / 3600;
st = new StringTokenizer(stemp,":");
process(Integer.valueOf(st.nextToken()),
Integer.valueOf(st.nextToken()),
Integer.valueOf(st.nextToken()),-1);
speed = tempspeed;
}
else
{
st = new StringTokenizer(st.nextToken(),":");
process(Integer.valueOf(st.nextToken()),
Integer.valueOf(st.nextToken()),
Integer.valueOf(st.nextToken()),1);
}
}
}
static int fff = 0;

static void process(int h,int m,int s,int flag)
{
int sumSecond = 0;
sumSecond += (s-ss);
sumSecond += ((m-mm)*60);
sumSecond += ((h-hh)*3600);
sumDist += (sumSecond * speed);
if(flag==1)
{
if(fff!=0)
System.out.println();
fff++;
display(h,m,s);
System.out.print(saveDigit(sumDist,2));
System.out.print(" km");
}
hh = h;
mm = m;
ss = s;
}

static String saveDigit(double d,int n)
{
StringBuffer sb = new StringBuffer("###.");
for(int i=0; i< n; i++)
sb.append("0");
DecimalFormat df2  = new DecimalFormat(sb.toString());
StringBuffer result = new StringBuffer(df2.format(d));
if(result.indexOf(".")==0)
result.insert(0,"0");
return result.toString();
}

static void display(int h,int m,int s)
{
if(h< 10)
System.out.print("0");
System.out.print(h+":");
if(m< 10)
System.out.print("0");
System.out.print(m+":");
if(s< 10)
System.out.print("0");
System.out.print(s+" ");
}
}

1. “火防女”在日语里的意思基本可以理解为火的守护的女。实际上根据她的工作内容，翻译成守火女会好一点。日语翻译就有这个问题，日语的假名就是汉字。然而这汉字的意思往往和中国的汉字不一样。这时候正确的翻译并不能直接把原文汉字拿来用。此外，每次听到防火女就感觉是一

2. 我还有个问题想请教一下，就是感觉对于新手来说，递归理解起来有些困难，不知有没有什么好的方法或者什么好的建议？

3. #!/usr/bin/env python
def cou(n):
arr =
i = 1
while(i<n):
arr.append(arr[i-1]+selfcount(i))
i+=1
return arr[n-1]

def selfcount(n):
count = 0
while(n):
if n%10 == 1:
count += 1
n /= 10
return count