Some input/output formats of topcoder

Source: Internet
Author: User

Since I participated in the TC competition in July of the previous year, I have never participated in it any more, because its input and output formats are hard to accept, and its page fonts are relatively small, it seems so hard for me... excuse me ~~ Lazy! However, I will try my best to participate in it later, in order to improve my programming skills.

Take the 144 question of SRM 200 Div 2 as an example to record the two input and output formats.

Problem Statement

Computers tend to store dates and times as single numbers which represent the number of seconds or milliseconds since a participant 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 "

SecondsIs 0, you shocould return "0: 0", while if seconds is 3661, you shocould return ".

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

-

SecondsWill be between 0 and 24*60*60-1 = 86399, aggressive.

Examples

0)

 

0

 

Returns: "0: 0"

 

 

1)

 

3661

 

Returns"

 

 

2)

 

5436

 

Returns: "1:30:36"

 

 

3)

 

86399

 

Returns: "23:59:59"

 

 

 

 

Java version

Public class time {

Public String whattime (INT seconds ){

Int H = secondds/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 = secondds/3600;

Int M = (seconds % 3600)/60;

Int S = seconds % 3600-M * 60;

Char Buf [40];

Sprintf (BUF, "% d: % d", H, M, S );

Return string (BUF );

}

};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.