TopCoder SRM 144 DIV2(200-point)
来源:互联网 发布:盒子直播平台源码 编辑:程序博客网 时间:2024/04/28 01:27
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:TimeMethod:whatTimeParameters:intReturns:stringMethod signature:string whatTime(int seconds)(be sure your method is public)Limits
Time limit (s):2.000Memory limit (MB):64Constraints
-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.
解析:
纯粹的秒数换算为时间的题目,只需要几个取模就可以了!
但是这是第一次用C++类来做题目,还是发现自己有很多不会的东西,就算是给自己学习添加动力吧!
而且,在topcoder上只需要将头文件和类提交,便可以了 所以主函数不用提交的!!!
代码:
#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;class Time{ public: string whatTime(int second){ int h = second/3600; int m = second/60%60; int s = second%60; char str[64]; sprintf(str, "%d:%d:%d", h,m,s); string ret = str; return ret; }};/*int main(){ Time time; int second; cin >> second; cout << time.whatTime(second) << endl; return 0;}*/
0 0
- TopCoder SRM 144 DIV2(200-point)
- TopCoder SRM 144 DIV2(550-point)
- TopCoder SRM 144 div2
- Topcoder SRM 514div2 500point
- topcoder 记录 srm 144 div2
- Topcoder Arena SRM 144 DIV2 1100 point 图遍历(非递归)+动态规划
- TopCoder SRM 144 DIV2 550points
- Topcoder SRM 144 Div2 1100 (树形dp)
- topcoder SRM 513 DIV2
- TopCoder SRM 543 DIV2
- topcoder-srm-233-div2
- Topcoder SRM Div2 Level2
- TOPCODER SRM 612 DIV2
- TOPCODER SRM 613 DIV2
- topcoder-srm-613-div2
- topcoder-srm-604-div2
- topcoder-srm-595-div2
- Topcoder SRM 676 div2
- 博客搬到CSDN了,以后就老实的呆在这儿吧~~
- php 大数据量及海量数据处理算法总结
- 当你学不进去的时候,试试“普瑞马法则”
- 如何关闭Microsoft Office上载中心
- 天勤论坛1000——1011解题笔记
- TopCoder SRM 144 DIV2(200-point)
- 为什么说博客、论坛的留言版块外链以无效
- oracle 下WITH CHECK OPTION用法
- ZOJ-3106
- 个人学习笔记开篇
- 大格局思维 应用1
- POJ 2593 DP 多YY才能行
- 黑马程序员_09面向对象(4)多态
- 重新开始打理博客了