AcWing 103. 电影(java using hashMap)
原题链接
简单
作者:
peilin
,
2020-06-20 04:41:50
,
所有人可见
,
阅读 709
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<Integer, Integer> langMap = new HashMap<>();
// store in a hashMap, key is the language and
// value is the number of scientists who can understand this language
int n = scanner.nextInt();
for(int i = 0; i < n; i++) {
int lang = scanner.nextInt();
langMap.put(lang, langMap.getOrDefault(lang, 0) + 1);
}
int m = scanner.nextInt();
int[] voiceLang = new int[m], subtitleLang = new int[m];
for(int i = 0; i < m; i++) {
soundLang[i] = scanner.nextInt();
}
for(int i = 0; i < m; i++) {
subtitleLang[i] = scanner.nextInt();
}
int cinemaInd = -1, maxHappy = -1;
for(int i = 0; i < m; i++) {
// time 2 with the number of scientists who can understand the cinema sound
// time 1 with the number of scientists who can understand the cinema sutitle
int happy = 2 * langMap.getOrDefault(soundLang[i], 0) + langMap.getOrDefault(subtitleLang[i], 0);
if(happy > maxHappy) {
cinemaInd = i;
maxHappy = happy;
}
}
System.out.println(cinemaInd + 1);
}
}