[SWEA] 주혁이의 복권 당첨

문제 보러가기

제한사항

두 정수의 범위는 img 이다.

당첨금을 나타내는 정수의 범위는 img 이다.

첫번째 생각

단순 구현 문제이다.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int tc=1;tc<=T;tc++) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			lotto[] lotto = new lotto[N];
			for(int i=0; i<N; i++) {
				lotto[i] = new lotto(sc.next(),sc.nextInt());
			}
			String[] s = new String[M];
			for(int i=0; i<M; i++) {
				s[i] = sc.next();
			}
			int prize = 0;
			for(int i=0; i<N; i++) {
                for(int j=0; j<M; j++) {
                    if ( verification(lotto[i].num, s[j]) )  {
                        prize += lotto[i].money;
                    }
                }
			}
			System.out.println("#"+tc+" "+prize);
		}
	}

	public static boolean verification(String snum , String s) {
			for (int i = 0; i < snum.length(); i++) {
				if (snum.charAt(i) != s.charAt(i) && snum.charAt(i) != '*') {
					break;
				} else if (i == snum.length()-1) {
					return true;
				}
			}
		return false; 
	}
	
	public static class lotto {
		String num;
		int money;
		lotto(String n, int m) {
			num = n;
			money = m;
		}
	}
}