桥寻:package _toutiao;
import java.util.*;
/**
* Created by kangqizhou on 2017/3/30.
*/
public class Main {
private static List<String> paragraph = new ArrayList<>();
private static List<String> paragraph2 = new ArrayList<>();
public static void main(String... args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
for (int i = 0; i < n; i++) {
String s = scanner.nextLine();
while (s.isEmpty())
s = scanner.nextLine();
paragraph.add(s.toLowerCase());
paragraph2.add(s);
}
for (int i = 0; i < m; i++) {
System.out.println(findResult(scanner.nextLine().toLowerCase()));
}
}
private static String findResult(String str) {
String[] strs = str.split(" ");
int max = 0;
int index = 0;
for (int i = index; i < paragraph.size(); i++) {
String[] line = paragraph.get(i).split(" ");
int result = findSame(strs, line);
if (result > max) {
index = i;
max = result;
}
}
return paragraph2.get(index);
}
public static int findSame(String array1[], String array2[]) {
int result = 0;
HashSet<String> hashSet = new HashSet<>();
HashSet<String> hashSet2 = new HashSet<>();
Collections.addAll(hashSet, array1);
Collections.addAll(hashSet2, array2);
for (String str : hashSet2) {
if (hashSet.contains(str)) {
result++;
}
}
return result;
}
}
挺简单的
投递字节跳动等公司9个岗位 >
0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: