Problem Statement | |||||||||||||
Computers tend to store dates and times as single numbers which represent the number of seconds or milliseconds since a particular date. Your task in this problem is to write a method whatTime, which takes an int,seconds, representing the number of seconds since midnight on some day, and returns a String formatted as "<H>:<M>:<S>". Here, <H> represents the number of complete hours since midnight, <M> represents the number of complete minutes since the last complete hour ended, and <S> represents the number of seconds since the last complete minute ended. Each of <H>, <M>, and <S> should be an integer, with no extra leading 0's. Thus, ifseconds is 0, you should return "0:0:0", while if seconds is 3661, you should return "1:1:1". | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Limits | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | seconds will be between 0 and 24*60*60 - 1 = 86399, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
做topcoder还要现下客户端,外国服务器连的慢,就直接把页面内容粘过来了……
题目大意:给出秒数,转换成“时:分:秒”格式。
题目分析:水无坑,算法简单易懂。
code:
public class Time{
public String whatTime(int seconds){
int h,m;
String ans;
h=seconds/3600;
seconds%=3600;
m=seconds/60;
seconds%=60;
ans=""+h+":"+m+":"+seconds;
return ans;
}
}
PS:准备期末考试,停了一段时间。从队长处得到topcoder的access,上来先水一发。
PSS:个人感觉topcoder写法较诡异……