diff --git a/src/P260_AlanSmithee.java b/src/P260_AlanSmithee.java new file mode 100644 index 0000000..f321dc5 --- /dev/null +++ b/src/P260_AlanSmithee.java @@ -0,0 +1,42 @@ +import java.util.*; + +public class P260_AlanSmithee { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Cuantos casos de prueba?"); + 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"); + } + } + } + + private static int vistos[] = new int[(int) ('z') - (int) ('a') + 1]; + + private static boolean isAnagram(String s1, String s2) { + 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; + } +} \ No newline at end of file