Created
January 1, 2017 12:28
-
-
Save enif-lee/e94bc5550f8dc2e9aa61bd3b1e9cd01f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AnagramDistance { | |
static Scanner sc = new Scanner(ClassLoader.getSystemResourceAsStream("problem/boj/AnagramDistance.testcase")); | |
private static class Anagram { | |
private String s1, s2; | |
public Anagram(String s1, String s2) { | |
this.s1 = s1; | |
this.s2 = s2; | |
} | |
public int getDistance () { | |
int result = 0; | |
int[] charactors = new int[59]; | |
for(int i = 0; i < s1.length(); i++) { | |
charactors[s1.charAt(i)-'A']++; | |
} | |
for(int i = 0; i < s2.length(); i++) { | |
charactors[s2.charAt(i)-'A']--; | |
} | |
for(int i = 0; i < charactors.length; i++) { | |
result += Math.abs(charactors[i]); | |
} | |
return result; | |
} | |
} | |
public static void main(String[] args) { | |
int T = sc.nextInt();sc.nextLine(); | |
for(int t = 1; t <= T; t++) { | |
System.out.println(String.format("Case #%d: %d", t, new Anagram(sc.nextLine(), sc.nextLine()).getDistance())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment