SRM 146 DIV2 250

問題を読む為の英単語

単語 意味
scoring 採点法
Yahtzee ヤッツィー(ダイスゲーム)
upward 上へ向かう
considered 熟考したうえで
instance 実例
end up 最後には、終わる

問題概要

サイコロをふって出た目のポイントで最大のものを出力せよ。
入力:5つダイスの値
出力:最大のスコア
スコアは下記条件で決まる。
①各々の出た目の値で最大のものをスコアとする。
②ただし、同じ目(ぞろ目)があった場合、その出た目は同じ目の数だけ倍数とする。
(3の目が3つ出た場合は,3*3*3=9point)

例示

{ 5, 3, 5, 3, 3 }
Returns: 10

{ 5, 3, 5, 3, 3 }
Returns: 10

回答コード(C#)

class YahtzeeScore
{
	public static int maxPoints(int[] toss){
		int[] score = new int[6]{0, 0, 0, 0, 0, 0};
		int max = 0;

		for(int i=0; i < toss.Length; i++){
			score [toss [i] % 6] += toss[i];
		}
		for (int i = 0; i < 6; i++) {
			if (max < score [i])
				max = score [i];
		}
		return max;
	}
}

よく使いそうなコード

1.初期化付き配列宣言

int[] score = new int[6]{0, 0, 0, 0, 0, 0};