Skip to content

Instantly share code, notes, and snippets.

@danicat
Created January 7, 2014 15:08
Show Gist options
  • Save danicat/8300659 to your computer and use it in GitHub Desktop.
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.
#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