Created
January 6, 2014 12:53
-
-
Save danicat/8282506 to your computer and use it in GitHub Desktop.
TopCoder SRM 145 Division 2 500 pts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <sstream> | |
using std::string; | |
using std::vector; | |
using std::stringstream; | |
class ExerciseMachine { | |
public: | |
int getPercentages(string time) { | |
int seconds = toSeconds(time); | |
int count = 0; | |
for(int i = 1; i < seconds; ++i) { | |
if( (i * 100) % seconds == 0 ) ++count; | |
} | |
return count; | |
} | |
int toSeconds(string time) { | |
vector<string> t = split(time, ':'); | |
return stoi( t[0] ) * 3600 + stoi( t[1] ) * 60 + stoi( t[2] ); | |
} | |
vector<string> split(string str, char delim = '\n') { | |
vector<string> parts; | |
stringstream ss { str }; | |
string part; | |
while( getline(ss, part, delim ) ) | |
parts.push_back( part ); | |
return parts; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment