TopCoder SRM 144 DIV2(200-point)
2014-01-30 00:17
441 查看
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) | ||||||||||||
|
解析:
纯粹的秒数换算为时间的题目,只需要几个取模就可以了!
但是这是第一次用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; } */
相关文章推荐
- 小朋友学TopCoder(2):第一个TopCoder程序--SRM144 DIV2 200-point
- TopCoder SRM 144 DIV2(550-point)
- 【topcoder】 SRM 144 div 2 200
- 小朋友学TopCoder(3):SRM144 DIV2 550-point
- Topcoder Arena SRM 144 DIV2 1100 point 图遍历(非递归)+动态规划
- 小朋友学TopCoder(4):SRM144 DIV2 1100-point
- 小朋友学TopCoder(5):SRM144 DIV1 550-point
- TopCoder 200 points 2-SRM 144 DIV 2 152.06/200 76.03%
- 小朋友学TopCoder(6):SRM144 DIV1 1100-point
- topcoder SRM 144 DIV 1 by First_Blood
- Topcoder: Problem Statement SRM 39 DIV1 500 Point
- Topcoder SRM 144 DIV 1
- TopCoder SRM 144 DIV1 BinaryCode
- TopCoder SRM 144 div2
- TopCoder SRM 144 DIV 2
- Topcoder SRM 144 Div2 1100 (树形dp)
- 小朋友学TopCoder(7):SRM726 DIV2 250-point
- TopCoder SRM 144 DIV2 550points
- 小朋友学TopCoder(8):SRM726 DIV2 500-point
- TopCoder SRM 727 Div2 500-point TwoDiagonals