티스토리 뷰

import java.util.*;

public class Main {

public static void main(String[] args) {
String str1 = "handshake";
String str2 = "shake hands";
str1 = str1.toUpperCase();
str2 = str2.toUpperCase();
int same = 0;
int answer = 0;
boolean flag = true;
List<String> list = new ArrayList<>();
List<String> list2 = new ArrayList<>();
List<String> listSum = new ArrayList<>();
for (int i = 0; i < str1.length()-1; i++) {

String temp = str1.substring(i, i + 2);
for (int j = 0; j < temp.length(); j++) {

if (!(temp.charAt(j) >= 'A' && temp.charAt(j) <= 'Z')) {
flag = false;
} else {

flag = true;
}

if (flag) {
list.add(temp);

}

}
}
for (int i = 0; i < str2.length()-1; i++) {
String temp = str2.substring(i, i + 2);
for (int j = 0; j < temp.length(); j++) {

if (!(temp.charAt(j) >= 'A' && temp.charAt(j) <= 'Z')) {
flag = false;
} else {

flag = true;
}

if (flag) {
list2.add(temp);

}

}
}
Collections.sort(list);
Collections.sort(list2);
for (int i = 0; i < list.size(); i++) {

String tmp = list.get(i);
if (list2.contains(tmp)) {

same++;
list2.remove(tmp);
}

listSum.add(tmp);
}

for(int i=0;i<list2.size();i++){
String tmp =list2.get(i);
listSum.add(tmp);
}

answer = (int)((float)same/(float)listSum.size())*65536;
System.out.println(answer);

}

}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함