/* Topcoder TCO 2016, Round 1A 250-Pointer EllysTimeMachine James S. Plank Tue Aug 21 15:26:35 EDT 2018 */ #include #include #include #include using namespace std; class EllysTimeMachine { public: string getTime(string time); }; string EllysTimeMachine::getTime(string time) { int h, m; char buf[20]; // This really only needs to be 6 characters, // but I'm using 20 to err on the high side. /* Convert the string into the two integers. */ sscanf(time.c_str(), "%d:%d", &h, &m); /* Convert hours to minutes, and minutes to hours. */ h %= 12; h *= 5; m /= 5; if (m == 0) m = 12; /* Create the return string using sprintf(). */ sprintf(buf, "%02d:%02d", m, h); return buf; }