Skip to content

Instantly share code, notes, and snippets.

@enif-lee
Created January 1, 2017 12:28
Show Gist options
  • Save enif-lee/e94bc5550f8dc2e9aa61bd3b1e9cd01f to your computer and use it in GitHub Desktop.
Save enif-lee/e94bc5550f8dc2e9aa61bd3b1e9cd01f 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 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