码迷,mamicode.com
首页 > 其他好文 > 详细

topcoder 的一些输入输出格式

时间:2014-07-18 20:12:23      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:style   java   color   strong   os   art   

    自从上年的11月份参加过TC的比赛后,就再也没有参加了,因为它的输入输出格式比较难接受,还有它的页面字体比较小,看得我很辛苦...藉口藉口~~懒而已!不过以后我会尽量去参加的,为了提高自己的编程能力。

    以 SRM 144  DIV 2 的 200 分题目为例,记录下两种输入输出格式吧。

    

   

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, if seconds 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"

 

 

 

    

 

   

JAVA 版

public class Time{

    public String whatTime(int seconds){

        int h = seconds / 3600;

        int m = (seconds % 3600) / 60;

        int s = seconds % 3600 - m * 60;

        return h + ":" + m + ":" + s;

    }

}

 

C++ 版

#include <iostream>

using namespace std;

 

class Time{

    public:

    string whatTime(int seconds)

    {

        int h = seconds / 3600;

        int m = (seconds % 3600) / 60;

        int s = seconds % 3600 - m * 60;

        char buf[40];

        sprintf(buf, "%d:%d:%d", h, m, s);

        return string(buf);

    }

};

topcoder 的一些输入输出格式,布布扣,bubuko.com

topcoder 的一些输入输出格式

标签:style   java   color   strong   os   art   

原文地址:http://www.cnblogs.com/windysai/p/3850364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!