Skip to content

Instantly share code, notes, and snippets.

@danicat
Created January 6, 2014 12:53
Show Gist options
  • Save danicat/8282506 to your computer and use it in GitHub Desktop.
Save danicat/8282506 to your computer and use it in GitHub Desktop.
TopCoder SRM 145 Division 2 500 pts
#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