topcoder吧 关注:404贴子:391
  • 2回复贴,共1

新人求助, SRM 144 DIV 2, 250-point

只看楼主收藏回复

不太懂tc的编译
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:TimeMethod:whatTimeParameters:intReturns:stringMethod signature:string whatTime(int seconds)(be sure your method is public)
Limits
Time limit (s):2.000Memory 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"
代码
#include<iostream>
using namespace std;
#include<string.h>
class Time {
public:
string whatTime(int seconds) {
int h = seconds/3600;
int m = seconds/60%60;
int s = seconds%60;
char str[64];
sprintf(str, "%d:%d:%d",h,m,s);
string ret = str;
//cout<<str<<endl;
return ret; }
};
void main() {
Time time;
//time.whatTime(0);
//time.whatTime(3661);
//time.whatTime(5436);
time.whatTime(86399);
}
为什么点击compile出现
Your code did not compile:
errors linking:
Time-stub.o: In function `main':
Time-stub.cc:(.text.startup+0x0): multiple definition of `main'
Time.o:Time-stub.cc:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status
我用的是VC++编译器


IP属地:美国1楼2015-05-22 18:57回复
    该怎么解决


    IP属地:美国2楼2015-05-22 18:57
    回复
      我懂了


      IP属地:美国来自iPhone客户端3楼2015-05-24 18:30
      回复