当我在 TopCoder 上提交代码时,它只给了我 200 分 SRM 的 60 分。
我认为算法有问题。
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
class Time
{
public:
string whatTime(int seconds)
{
int hours=0, minutes=0, secs=0;
ostringstream cHours, cMinutes, cSeconds;
string sHours, sMinutes, sSeconds;
string theReturns;
while (seconds > 0)
{
if (seconds > 3600)
{
hours++;
seconds -= 3600;
}
else if (seconds > 60)
{
minutes++;
seconds -= 60;
} else {
secs ++;
seconds--;
}
}
cHours << hours;
cMinutes << minutes;
cSeconds << secs;
sHours = cHours.str() + ":";
sMinutes = cMinutes.str() + ":";
sSeconds = cSeconds.str();
theReturns = sHours + sMinutes + sSeconds;
return (theReturns);
}
};
/* Main Function for Me, I didn't submitted it on TopCoder, they only want the class */
int main()
{
Time myTime;
cout << myTime.whatTime(3661);
return (0);
}