TopCoder SRM 145 DIV 1 Easy 練習

問題

数列が与えられるので、合計に対する各要素の割合を計算しなさい。ただし端数は割合の多いものに与えていくとする。

やるだけ。

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;

public class Bonuses {
    public int[] getDivision(int[] points) {
        int[] res = new int[points.Length];
        bool[] ch = new bool[points.Length];
        int per = 100, sum = 0;

        foreach (int n in points) sum += n;
        for (int i = 0; i < points.Length; ++i)
        {
            res[i] = (int)(100.0 * points[i] / sum);
            per -= res[i];
        }

        for (int i = 0; i < per; ++i)
        {
            int max = 0, target = 0;
            for (int j = 0; j < points.Length; ++j)
            {
                if (ch[j]) continue;
                if (max < points[j])
                {
                    max = points[j];
                    target = j;
                }
            }
            res[target]++;
            ch[target] = true;
        }
        return res;
    }
}