-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNews_Clustering_17677.java
More file actions
60 lines (50 loc) · 1.75 KB
/
News_Clustering_17677.java
File metadata and controls
60 lines (50 loc) · 1.75 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.ArrayList;
public class News_Clustering_17677 {
public static void main(String[] args) {
solution("FRANCE", "FRENCH");//��Ʈ
}
public static int solution(String str1, String str2) {
ArrayList<String> str1Array = new ArrayList<String>();
ArrayList<String> str2Array = new ArrayList<String>();
for(int i = 0; i < str1.length()-1; i++) {
String temp = str1.substring(i, i+2).toLowerCase();
if(temp.matches("^[a-z]*$")) {
str1Array.add(temp);
}
}
for(int i = 0; i < str2.length()-1; i++) {
String temp = str2.substring(i, i+2).toLowerCase();
if(temp.matches("^[a-z]*$")) {
str2Array.add(temp);
}
}
ArrayList<String> sum = new ArrayList<String>();
ArrayList<String> con = new ArrayList<String>();
for(int i = 0; i < str1Array.size(); i++) {
for(int j = 0; j < str2Array.size(); j++) {
if(str1Array.get(i).equals(str2Array.get(j))) {
con.add(str1Array.get(i));
str1Array.remove(i);
str2Array.remove(j);
i--;
j = -1;
break;
}
}
}
sum.addAll(str1Array);
sum.addAll(str2Array);
sum.addAll(con);
float zacquard;
if(str1Array.size()==0 & str2Array.size()==0) {
zacquard = 65536;
} else {
float conNumber = con.size();
float sumNumber = sum.size();
zacquard = conNumber / sumNumber ;
zacquard = zacquard * 65536;
}
int answer = (int) zacquard;
return answer;
}
}