Skip to content

Instantly share code, notes, and snippets.

@gennad
Created August 24, 2012 23:02
Show Gist options
  • Save gennad/3456887 to your computer and use it in GitHub Desktop.
Save gennad/3456887 to your computer and use it in GitHub Desktop.
144-2-1
#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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment