LoginSignup
0
0

More than 5 years have passed since last update.

SRM146 div2 250

Posted at

問題文概略

1~6の目が出るサイコロを5回投げる。
出た目がポイントとなり、目が被ったらその目の数を足しあわせてポイントとする。
ポイントの最大値を求めよ。
例)
1,2,3,5,6 →ポイントは6
1,4,4,3,5 →ポイントは4+4=8

書いたコード

public class YahtzeeScore {
    public int maxPoints(int[] toss) {
        //どの目が何回出たかを入れる配列
        int a[]=new int[6];
        //ポイント
        int max=0;
        //どの目が何回出たかを配列に入れる
        for(int i=0; i<toss.length; i++) {
            a[toss[i]-1]++;
        }
        //上の配列から最大点数を計算
        for (int k=0; k<6; k++){
            if(max<a[k]*(k+1) == true) {
                max = a[k]*(k+1);
            }
        }
        return max;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0