Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.02.07 - [BOJ] 1919. 애너그램 만들기 #8

Closed
suhyunsim opened this issue Feb 14, 2021 · 0 comments
Closed

21.02.07 - [BOJ] 1919. 애너그램 만들기 #8

suhyunsim opened this issue Feb 14, 2021 · 0 comments
Assignees
Labels
브론즈 BOJ - 브론즈 성공 맞은 문제

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Feb 14, 2021

문제

핵심 아이디어

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q1919;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Character> aList = new ArrayList<>();
        ArrayList<Character> bList = new ArrayList<>();
        String a = sc.nextLine();
        String b = sc.nextLine();
        for (int i = 0; i < a.length(); i++) {
            aList.add(a.charAt(i));
        }
        for (int i = 0; i < b.length(); i++) {
            bList.add(b.charAt(i));
        }
        Collections.sort(aList);
        Collections.sort(bList);

        for (int i = 0; i < aList.size(); i++) {
            for (int j = 0; j < bList.size(); j++) {
                if (aList.get(i) == bList.get(j)) {
                    aList.remove(aList.get(i));
                    bList.remove(bList.get(j));
                    i--;
                    break;
                }
            }
        }
        int cnt = aList.size() + bList.size();
        System.out.println(cnt);
        sc.close();
    }
}
package main.java.com.poogle.BOJ.Q1919;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int count = 0;
        String word1 = scan.next();
        String word2 = scan.next();

        // 단어별로 알파벳 담을 배열
        int[] arr1 = new int[26];
        int[] arr2 = new int[26];

        for (int i = 0; i < word1.length(); i++)
            arr1[word1.charAt(i) - 'a']++;

        for (int i = 0; i < word2.length(); i++)
            arr2[word2.charAt(i) - 'a']++;

        // 각 알파벳 별로 차이만큼(절댓값) 제거하기
        for (int i = 0; i < 26; i++)
            if (arr1[i] != arr2[i])
                count += Math.abs(arr1[i] - arr2[i]);

        System.out.println(count);
        scan.close();
    }
}
@suhyunsim suhyunsim self-assigned this Feb 14, 2021
@suhyunsim suhyunsim changed the title 21.02.09 - [BOJ] 1919. 애너그램 만들기 21.02.07 - [BOJ] 1919. 애너그램 만들기 Feb 14, 2021
@suhyunsim suhyunsim added this to the 2월 1주 차 milestone Feb 14, 2021
@suhyunsim suhyunsim added the 브론즈 BOJ - 브론즈 label Mar 5, 2021
@suhyunsim suhyunsim added 구현 성공 맞은 문제 labels Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
브론즈 BOJ - 브론즈 성공 맞은 문제
Projects
None yet
Development

No branches or pull requests

1 participant