배열 한접시
[백준] 11328번: StrFry [Java]
NaZZU
2024. 4. 19. 18:50
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
|
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
sc.nextLine();
String arr1;
String arr2;
for (int i =0; i < N; i++)
{
boolean res = true;
int[] alphabet = new int[26];
String[] input = sc.nextLine().split(" ");
arr1 = input[0];
arr2 = input[1];
for (int j = 0; j < arr1.length(); j++)
alphabet[arr1.charAt(j) - 'a']++;
for (int k = 0; k < arr2.length(); k++)
alphabet[arr2.charAt(k) - 'a']--;
for (int l = 0; l < 26; l++)
if (alphabet[l] != 0)
res = false;
System.out.println(res ? "Possible" : "Impossible");
}
}
}
|
cs |
매 루프 반복 후 boolean 변수 res를 다시 true로 초기화 해줘야 하는데 그거를 깜빡해서 오류가 났었다.