Skip to content

Instantly share code, notes, and snippets.

@enif-lee
Created January 1, 2017 12:26
Show Gist options
  • Save enif-lee/35faf31f98c7fd95d014a1392c84da24 to your computer and use it in GitHub Desktop.
Save enif-lee/35faf31f98c7fd95d014a1392c84da24 to your computer and use it in GitHub Desktop.
package problem.boj;
import java.util.Scanner;
/**
* Created by Jinseoung on 2017-01-01.
*/
public class Anagram {
static boolean isAnagram (String s1, String s2) {
int[] charactors = new int[59];
for(int i = 0; i < s1.length(); i++){
int index = s1.charAt(i) - 'A';
charactors[index]++;
}
for(int i = 0; i < s2.length(); i++){
int index = s2.charAt(i) - 'A';
charactors[index]--;
}
for(int i = 0 ; i < charactors.length; i++) {
if(charactors[i] != 0) return false;
}
return true;
}
static String getStringIsAnagram (String s1, String s2) {
return s1 + " & " + s2 + " are " + (isAnagram(s1,s2) ? "" : "NOT ") + "anagrams.";
}
static Scanner sc = new Scanner(ClassLoader.getSystemResourceAsStream("problem/boj/Anagram.testcase"));
public static void main(String[] args) {
int N = sc.nextInt();
for(int t = 0; t < N; t++) {
System.out.println(getStringIsAnagram(sc.next(), sc.next()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment