Problem Statement | |||||||||||||
This task is about the scoring in the first phase of the die-game Yahtzee, where five dice are used. The score is determined by the values on the upward die faces after a roll. The player gets to choose a value, and all dice that show the chosen value are considered active. The score is simply the sum of values on active dice. Say, for instance, that a player ends up with the die faces showing 2, 2, 3, 5 and 4. Choosing the value two makes the dice showing 2 active and yields a score of 2 + 2 = 4, while choosing 5 makes the one die showing 5 active, yielding a score of 5. Your method will take as input a int[] toss, where each element represents the upward face of a die, and return the maximum possible score with these values. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | toss will contain exactly 5 elements. | ||||||||||||
- | Each element of toss will be between 1 and 6, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
这首题比较容易,,就是练练手
public class YahtzeeScore {
public static int maxPoints(int[] toss) {
int len = toss.length;
int t[] = new int[7];
int max = 0;
for (int i = 0; i < len; i++)
t[toss[i]] += toss[i];
for (int i = 1; i <= 6; i++)
if (t[i] > max)
max = t[i];
return max;
}
}