44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
import java.util.*;
|
|
|
|
public class P260_AlanSmithee {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int casos = sc.nextInt();
|
|
sc.nextLine();
|
|
|
|
for (int i = 0; i < casos; i++) {
|
|
String frase1 = sc.nextLine().toLowerCase();
|
|
String frase2 = sc.nextLine().toLowerCase();
|
|
if(isAnagram(frase1, frase2)) {
|
|
System.out.println("SI");
|
|
} else {
|
|
System.out.println("NO");
|
|
}
|
|
}
|
|
sc.close();
|
|
}
|
|
|
|
private static boolean isAnagram(String s1, String s2) {
|
|
// (int) ('z') - (int) ('a') + 1 == 27
|
|
int vistos[] = new int[27];
|
|
|
|
for (int j = 0; j < s1.length(); j++){
|
|
char c = s1.charAt(j);
|
|
if(!Character.isLowerCase(c)) continue;
|
|
vistos[(int)(c) - (int)('a')]++;
|
|
}
|
|
for (int j = 0; j < s2.length(); j++){
|
|
char c = s2.charAt(j);
|
|
if(!Character.isLowerCase(c)) continue;
|
|
vistos[(int)(c) - (int)('a')]--;
|
|
}
|
|
for (int j = 0; j < vistos.length; j++){
|
|
if (vistos[j] != 0){
|
|
vistos[j] = 0;
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|