SWEA_D3_6900_주혁이의 복권 당첨

SWEA

6900. 주혁이의 복권 당첨

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution {
	static int T, N, M;
	static int WinningNum[][];
	static int Prize[][];
	static boolean check;

	static StringTokenizer st;

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		T = Integer.parseInt(in.readLine().trim());
		for (int test_case = 1; test_case <= T; test_case++) {
			st = new StringTokenizer(in.readLine());

			N = Integer.parseInt(st.nextToken());
			M = Integer.parseInt(st.nextToken());

			WinningNum = new int[N][8];
			Prize = new int[N][2];

			for (int i = 0, j = 0; i < N; i++, j = 0) {
				Arrays.fill(WinningNum[i], -1);
				st = new StringTokenizer(in.readLine());

				for (char c : st.nextToken().toCharArray()) {
					if (Character.isDigit(c)) {
						WinningNum[i][j] = c - '0';
					}
					j++;
				}
				Prize[i][0] = Integer.parseInt(st.nextToken());
			}

			for (int i = 0; i < M; i++) {
				CheckNum(in.readLine().toCharArray());
			}

			System.out.println("#" + test_case + " " + getSum());

		}
	}

	private static void CheckNum(char[] num) {
		for (int i = 0, j = 0; i < N; i++, j = 0) {
			check = true;
			for (char c : num) {
				if (WinningNum[i][j] != -1 && WinningNum[i][j] != c - '0') {
					check = false;
					break;
				}
				j++;
			}
			if(check) {
				Prize[i][1]++;
				return;
			}
		}
	}

	private static int getSum() {
		int sum = 0;
		for (int i = 0; i < N; i++) {
			sum += Prize[i][1] * Prize[i][0];
		}
		return sum;
	}
}


© 2019. All rights reserved.

Powered by Hydejack v8.4.0