codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  interview problem  ace333 at 08:42 on Wednesday, September 21, 2005
 

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;
}



I think this is c++ and I'm just curious what this particular function does. Can anyone spot any errors in the particular code. Are there any other inefficiencies in the the code....

Is there another way to implement the code.


  Re: interview problem  Yusairi at 02:36 on Thursday, September 22, 2005
 

hi ace3333,

the code seem working fine for me.
that function working to convert the datetime data
Now() and convert it on the format that had been
remark on that function. please explain more what you
need.


  Re: interview problem  ace333 at 07:29 on Thursday, September 22, 2005
 

Just wondering what the code does, I don't really understand what you said in the last post.

If you can run the code can you give me a sample input and output

  Re: interview problem  javabits at 17:28 on Thursday, September 22, 2005
 

It looks like

The first loop subtracts a day until you get to the previous Sunday.

The second loop subtracts an hour from the time until you get to midnight.

The third loop subtracts a minute from the time until you get to the beginning of the hour.

The fourth loop subtracts a second from the time until you get to beginning of the minute.

This should return:
a) If the input wasn't a Sunday should return the previous Sunday at midnight.

b) If it was a Sunday should return the current Sunday at midnight.

Possible changes could of course include removing the loops for the hour, minutes and seconds as you could just set those all to 00 in the string, (thus avoiding the worst case scenario of 11, 59 and 59 in your loops).

The first loop could probably be changed to a case/switch statement with different cases for the different days of the week.

The bool seems to be unused.

Looks like the substr for all the time comparisons is off by an index of 1.

semper fi...



  Re: interview problem  syong at 14:44 on Thursday, May 24, 2007
 

Can i know what program is that?
cause I am having the same problem as well.
many thanks.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
• Global.Mapper.v15.2.3.b060614
• Geometric_Glovius_Pro_v3.6.1
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1
• VoluMill.NEXION.6
• VERO.SurfCAM.v2014


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2014