SRM144 DIV2



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

 
Class:Time
Method:whatTime
Parameters:int
Returns:String
Method signature:String whatTime(int seconds)
(be sure your method is public)

Limits

 
Time limit (s):2.000
Memory limit (MB):64

Constraints

-seconds will be between 0 and 24*60*60 - 1 = 86399, inclusive.

Examples

0) 
 
0
Returns: "0:0:0"
 
1) 
 
3661
Returns: "1:1:1"
 
2) 
 
5436
Returns: "1:30:36"
 
3) 
 
86399
Returns: "23:59:59"
 

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.

题意:给出秒数,用h:m:s形式显示出来

 思路:        h=seconds / 3600    m = seconds % 3600 / 60      s = seconds % 60

           注意:在用java实现时,类名需要设置有公共的,否则测试时会不成功

代码如下:

   

public class Time
{
	public String whatTime(int seconds)
	{
		int h = seconds / 3600;
		int m = seconds % 3600 / 60;
		int s = seconds % 60;
		
		String ans = h + ":" + m + ":" + s;
		
		return ans;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值