|
Hi everyone, this is my first thread so i hope i am giving enough information.
Well i have this interview problem shown below:
time_t normalise(time_t input_time)
{
bool finished;
// This produces a formatted time string like:
// Thu_Nov_24_18:22:48_1986
string str_time = format_time( input_time );
while( str_time.substr(1,3) != "Sun")
{
input_time -= 24*60*60;
str_time = format_time( input_time );
}
while( str_time.substr(11,2) != "00" )
{
input_time -= 60*60;
str_time = format_time( input_time );
}
while( str_time.substr(14,2) != "00")
{
str_time = format_time( input_time );
input_time -= 60;
}
while( str_time.substr(17,2) != "00")
{
input_time -= 1;
str_time = format_time( input_time );
}
return input_time;
}
Now the company has asked me to point out what the code does
The two bugs in the code.
They want to know the inefficiences of the code.
They also want me to write a better implementation of the code knowing that time_t represents the time in seconds since the epoch which is 1st jan 1 00:00:00 1970.
What i am stuck on is the last question and i can only point out 1 bug but you are welcome to have a go at all the questions and i can then see the answers that i do have are correct or not.
Thanks for whoever can help me as this is really making my head hurt.
Thanks
Iffy.
|
|
|
|
|
|
|
|