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로 초기화 해줘야 하는데 그거를 깜빡해서 오류가 났었다.
'배열 한접시' 카테고리의 다른 글
[백준] 1919번 애너그램 만들기 [Java] (1) | 2024.04.19 |
---|---|
[백준] 13300번: 방 배정 [Java] (0) | 2024.04.19 |
[백준] 두 수의 합 [C#] (1) | 2024.04.19 |
[백준] 1475번: 방 번호 [Java] (0) | 2024.04.18 |
[백준] 10808번: 알파벳 개수 [Java] (0) | 2024.04.18 |