PostAddsense


AustrianLotto Topcoder



public class AustrianLotto
{
    public int[] evaluate(String drawing, String[] picks) {
        boolean[] n = new boolean[46];
        String[] sp = drawing.split(" ");
        for (int i=0; i < 6; i++)
            n[Integer.parseInt(sp[i])] = true;

        int[] res = new int[7];

        for (int i=0; i < picks.length; i++) {
            sp = picks[i].split(" ");
            int cnt=0;
            for (int j=0; j < 6; j++)
                if(n[Integer.parseInt(sp[j])]) cnt++;

            res[cnt]++;
        }

        return res;
    }
}


Explanation

길이 45인 boolean배열을 만들고 drawing에 있는 숫자를 색인 자리에 넣고 값을 true로 둔다. picks배열에서 숫자를 넣어 true면 cnt를 증가시킨다.