Trang

Thứ Năm, 6 tháng 1, 2011

3254. Rock-Paper-Scissors

import java.io.*;

public class Main {

    /**
     * http://acm.tju.edu.cn/toj/showp3254.html
     * @author hunglee
     */
    public static void main(String[] args) throws IOException {
        
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(
                new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(System.out);
        
        int R, N;
        String sven, friend[];
        in.nextToken();
        R = (int) in.nval;
        in.nextToken();
        sven = in.sval;
        in.nextToken();
        N = (int) in.nval;
        friend = new String[N];
        for (int i = 0; i < N; ++i) {
            in.nextToken();
            friend[i] = in.sval;
        }
        
        int scores = 0, maxScores = 0;
        int[] r, p, s;
        r = new int[R];
        p = new int[R];
        s = new int[R];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < R; ++j) {
                scores += getPoint(sven.charAt(j), friend[i].charAt(j));
                switch (friend[i].charAt(j)) {
                case 'S':
                    ++s[j]; break;
                case 'P':
                    ++p[j]; break;
                default:
                    ++r[j]; break;
                }
            }
        }
        for (int j = 0; j < R; ++j)
            maxScores += Math.max(s[j] + 2 * p[j], Math.max(
                    p[j] + 2 * r[j], r[j] + 2 * s[j]));
        out.println(scores + "\n" + maxScores);
        out.flush();
    }
    
    private static int getPoint(char ch, char ch2) {
        switch (ch) {
        case 'S':
            switch (ch2) {
            case 'R': return 0;
            case 'P': return 2;
            default:  return 1;
            }
        case 'P':
            switch (ch2) {
            case 'R': return 2;
            case 'P': return 1;
            default:  return 0;
            }
        default:
            switch (ch2) {
            case 'R': return 1;
            case 'P': return 0;
            default:  return 2;
            }
        }
    }

}

Không có nhận xét nào:

Đăng nhận xét