题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858

比较简单。

代码如下:

#include <iostream>
#include <vector> using namespace std; class YahtzeeScore
{
public:
int maxPoints(vector <int> toss);
}; int YahtzeeScore::maxPoints(vector<int> toss)
{
int i, j;
int size = toss.size();
int maxP = 0;
int sum; for (i = 0; i < size; i++) {
sum = 0;
for (j = 0; j < size; j++) {
if (toss[i] == toss[j]) {
sum += toss[i];
}
}
if (sum > maxP) {
maxP = sum;
}
}
return maxP;
}
04-21 08:21