Created
January 1, 2017 12:26
-
-
Save enif-lee/35faf31f98c7fd95d014a1392c84da24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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