Skip to content

Instantly share code, notes, and snippets.

@gennad
Created August 24, 2012 23:02
Show Gist options
  • Select an option

  • Save gennad/3456887 to your computer and use it in GitHub Desktop.

Select an option

Save gennad/3456887 to your computer and use it in GitHub Desktop.

Revisions

  1. gennad created this gist Aug 24, 2012.
    38 changes: 38 additions & 0 deletions 144-2-1.cc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <assert.h>

    class Time {
    public:
    std::string whatTime(int seconds);
    };


    std::string Time::whatTime(int seconds) {
    std::stringstream out;
    std::string hours_s, mins_s, secs_s;
    int hours, mins, secs;

    hours = seconds / (60 * 60);
    out << hours;
    hours_s = out.str();
    out.str("");

    seconds = seconds - (hours * 60 * 60);
    mins = seconds / 60;
    seconds = seconds - (mins * 60);
    secs = seconds;

    out << secs;

    secs_s = out.str();
    out.str("");

    out << mins;
    mins_s = out.str();
    out.str("");

    out << hours_s << ":" << mins_s << ":" << secs_s;
    return out.str();
    }