Created
January 7, 2014 15:08
-
-
Save danicat/8300659 to your computer and use it in GitHub Desktop.
TopCoder SRM 146 Division 2 250 pts Since you need to calculate the sum of repeated values it seemed natural to me to use a hash table (map) to store the respective sums. Once you have that sum stored you just need to return the highest sum with a simple max algorithm.
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 <vector> | |
#include <map> | |
using namespace std; | |
class YahtzeeScore { | |
public: | |
int maxPoints(vector<int> toss) { | |
map<int, int> sum; | |
for(auto p : toss) { | |
sum[p] += p; | |
} | |
int max = 0; | |
for(auto p : sum) { | |
max = p.second > max ? p.second : max; | |
} | |
return max; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment