import java.util.*;

class Solution {
    public int solution(String str1, String str2) {
        int count = 0;
        PriorityQueue<String> pq1 = new PriorityQueue<>();
        PriorityQueue<String> pq2 = new PriorityQueue<>();
        
        str1 = str1.toUpperCase(); str2 = str2.toUpperCase();
        
        for(int i=0; i<str1.length()-1; i++) {
            char c1 = str1.charAt(i); char c2 = str1.charAt(i+1);
            if(!(c1>='A'&&c1<='Z'&&c2>='A'&&c2<='Z')) { continue; }
            
            pq1.add(String.valueOf(c1)+String.valueOf(c2));
        }
        
        for(int i=0; i<str2.length()-1; i++) {
            char c1 = str2.charAt(i); char c2 = str2.charAt(i+1);
            if(!(c1>='A'&&c1<='Z'&&c2>='A'&&c2<='Z')) { continue; }
            
            pq2.add(String.valueOf(c1)+String.valueOf(c2));
        }
        
        String[] s1 = new String[pq1.size()];
        String[] s2 = new String[pq2.size()];
        
        if(s1.length==0 && s2.length==0) { return 65536; }
        
        for(int i=0; i<s1.length; i++) { s1[i] = pq1.poll(); }
        for(int i=0; i<s2.length; i++) { s2[i] = pq2.poll(); }
        
        for(int i=0; i<s1.length; i++) {
            for(int j=0; j<s2.length; j++) {
                if(s1[i].equals(s2[j])) {
                    count++;
                    s2[j] = "0";
                    break;
                }
            }
        }
        
        double rate = (double)count/(s1.length+s2.length-count);
        
        return (int)(rate*65536);
    }
}

'Problem Solving > Programmers' 카테고리의 다른 글

[Level 2] 전화번호 목록  (0) 2022.03.31
[Level 2] 튜플  (0) 2022.03.31
[Level 2] 짝지어 제거하기  (0) 2022.03.31
[Level 2] 행렬 테두리 회전하기  (0) 2022.03.31
[Level 2] 타겟 넘버  (0) 2022.03.31