[프로그래머스] [1차] 뉴스 클러스터링
2020. 4. 1. 14:33ㆍ프로그래머스/카카오
import java.util.*;
class Solution {
public int solution(String str1, String str2) {
int answer = 0;
double result = 0;
List<String> multiset = new ArrayList<>();
List<String> multiset2 = new ArrayList<>();
List<String> multisection = new ArrayList<>();
for(int i=0; i<=str1.length()-2; i++){
if (alphabetTest(str1.charAt(i)) && alphabetTest(str1.charAt(i+1))){
if(i!=str1.length()-2){
multiset.add(str1.substring(i,i+2));
}else{
multiset.add(str1.substring(i));
}
}
}
for(int i=0; i<=str2.length()-2; i++){
if (alphabetTest(str2.charAt(i)) && alphabetTest(str2.charAt(i+1))){
if(i!=str2.length()-2){
multiset2.add(str2.substring(i,i+2));
}else{
multiset2.add(str2.substring(i));
}
}
}
for(int i=0; i<multiset.size(); i++){
if(checkContains(multiset2,multiset.get(i))){
multisection.add(multiset.get(i));
}
}
if((multiset.size()+multiset2.size()-multisection.size())!=0){
result = (double)multisection.size()/(double)(multiset.size()+multiset2.size()-multisection.size());
}else{
result = 1;
}
answer = (int)(result * 65536);
return answer;
}
public boolean alphabetTest(char c){
if( 65<=c && c<=90){
return true;
}
else if( 97<=c && c<=122){
return true;
}
else{
return false;
}
}
public boolean checkContains(List<String> multiset2, String s){
for(int i=0; i<multiset2.size(); i++){
if(multiset2.get(i).equalsIgnoreCase(s)){
multiset2.set(i,"사용됨");
return true;
}
}
return false;
}
}
'프로그래머스 > 카카오' 카테고리의 다른 글
[프로그래머스] 카카오프렌즈 컬러링북 (0) | 2020.04.04 |
---|---|
[프로그래머스] 오픈채팅방 (0) | 2020.04.02 |
[프로그래머스] 크레인 인형뽑기 (0) | 2020.04.01 |
[프로그래머스] [1차] 다트게임 (0) | 2020.03.31 |
[프로그래머스] 문자열압축 (0) | 2020.03.30 |