-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordDecoder.java
41 lines (38 loc) · 1.08 KB
/
PasswordDecoder.java
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
package boj.third;
import java.util.Scanner;
public class PasswordDecoder {
public static String solution(int n, int[] code, String str){
int [] cnt = new int[53];
for (int i = 0; i < n; i++){
char word= str.charAt(i);
int wordCode;
if (word == ' '){
wordCode = 0;
} else if (word <= 90){
wordCode = word - 64;
} else {
wordCode = word - 70;
}
cnt[wordCode] += 1;
}
for (int i = 0; i < n; i++){
int wordCode = code[i];
if (cnt[wordCode] == 0) {
return "n";
}
cnt[wordCode] -= 1;
}
return "y";
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] code = new int[n];
for (int i = 0; i < n; i++){
code[i] = sc.nextInt();
}
sc.nextLine();
String str = sc.nextLine();
System.out.println(solution(n, code, str));
}
}