📄 3449771_wa.java
字号:
import java.util.*;
import java.io.*;
public class Main {
private BufferedReader br;
class Documents {
String str;
HashMap <String, Integer> hm;
public Documents() {
str = "";
hm = new HashMap <String, Integer> ();
}
private void add(String line) {
str += " " + line;
}
private String parse(String str) {
String ret = "";
for (int i = 0; i < str.length(); i++) {
if (Character.isLetter(str.charAt(i))) {
ret += str.charAt(i);
}
}
return ret;
}
private void getTerms() {
StringTokenizer st = new StringTokenizer (str);
while (st.hasMoreTokens()) {
String tmp = parse(st.nextToken());
if (tmp.length() == 0) {
continue;
}
int cnt = 0;
if (hm.containsKey(tmp)) {
cnt = hm.get(tmp).intValue();
hm.remove(tmp);
}
hm.put(tmp, cnt + 1);
}
}
}
public static void main(String [] args) {
try {
new Main().run();
}
catch (IOException ie) {
while (true) {
System.out.println("I love Shengqi");
}
}
}
private void run() throws IOException {
br = new BufferedReader (new InputStreamReader (System.in));
LinkedList <Documents> ld = new LinkedList <Documents> ();
String line;
while (true) {
line = br.readLine();
if ("----------".equals(line)) {
break;
}
Documents documents = new Documents();
documents.add(line);
while (true) {
line = br.readLine();
if ("----------".equals(line)) {
break;
}
documents.add(line);
}
documents.getTerms();
ld.addLast(documents);
}
double score;
Documents first = ld.get(0);
for (int i = 1; i < ld.size(); i++) {
Documents now = ld.get(i);
score = 0.0;
for (String str : now.hm.keySet()) {
if (first.hm.containsKey(str)) {
int a = first.hm.get(str);
int b = now.hm.get(str);
score += Math.sqrt((double)(a * b));
}
}
System.out.format("%.2f\n", score);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -