https://www.acmicpc.net/problem/1919
import java.util.Scanner;
class Main
{
public static int[] getAlphabetCountArray(String str) {
int[] count = new int[26];
for (int i = 0; i < str.length(); i++)
count[str.charAt(i) - 'a']++;
return count;
}
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
int[] countA = getAlphabetCountArray(a);
int[] countB = getAlphabetCountArray(b);
int ans = 0;
for (int i = 0; i < 26; i++)
ans += Math.abs(countA[i] - countB[i]);
System.out.println(ans);
}
}
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String word1 = br.readLine();
String word2 = br.readLine();
Long ans = 0l;
HashMap<String,Long> hashmap = new HashMap<>();
for(int i=0;i<word1.length();i++){
String w = String.valueOf(word1.charAt(i));
if(hashmap.containsKey(w)){
hashmap.put(w,hashmap.get(w)+1l);
}else{
hashmap.put(w,1l);
}
}
for(int i=0;i<word2.length();i++){
String w = String.valueOf(word2.charAt(i));
if(hashmap.containsKey(w) && hashmap.get(w)>0l){
hashmap.put(w,hashmap.get(w)-1l);
}else{
ans++;
}
}
for(Long l: hashmap.values()){
ans+=l;
}
System.out.println(ans);
}
}
'Problem Solving > 구현' 카테고리의 다른 글
BOJ13223 소금폭탄 (0) | 2024.01.24 |
---|---|
BOJ1543 문서검색 (0) | 2024.01.24 |
BOJ2744 대소문자 바꾸기 (0) | 2024.01.24 |
자바 문법 - 진수 바꾸기 (3진법뒤집기) (0) | 2023.11.22 |
비밀지도- 2진수 만들기 (1) | 2023.11.21 |