|
| 1 | +import java.io.BufferedReader; |
| 2 | +import java.io.IOException; |
| 3 | +import java.io.InputStreamReader; |
| 4 | +import java.util.ArrayList; |
| 5 | + |
| 6 | +class PhoneNumber { |
| 7 | + String name; |
| 8 | + int phoneNumber; |
| 9 | + int frequency; |
| 10 | + |
| 11 | + public PhoneNumber(String name, int phoneNumber) { |
| 12 | + this.name = name; |
| 13 | + this.phoneNumber = phoneNumber; |
| 14 | + frequency = 0; |
| 15 | + } |
| 16 | + |
| 17 | + public void add() { |
| 18 | + frequency++; |
| 19 | + } |
| 20 | + |
| 21 | + public void printInfo() { |
| 22 | + System.out.println(name + " " + phoneNumber + " " + frequency); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +public class ccchk08j3 { |
| 27 | + |
| 28 | + public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
| 29 | + |
| 30 | + public static void main(String[] args) throws IOException { |
| 31 | + int n = readInt(); |
| 32 | + |
| 33 | + ArrayList<PhoneNumber> list = new ArrayList<PhoneNumber>(); |
| 34 | + |
| 35 | + String[] input; |
| 36 | + for (int i = 0; i < n; i++) { |
| 37 | + input = readSpaceInput(); |
| 38 | + list.add(new PhoneNumber(input[0], Integer.parseInt(input[1]))); |
| 39 | + } |
| 40 | +// for (int i = 0; i < list.size(); i++) { |
| 41 | +// System.out.print(list.get(i).name + " "); |
| 42 | +// System.out.println(list.get(i).phoneNumber); |
| 43 | +// } |
| 44 | + |
| 45 | + int d = readInt(); |
| 46 | + int phoneNumber; |
| 47 | + |
| 48 | + for (int i = 0; i < d; i++) { |
| 49 | + phoneNumber = readInt(); |
| 50 | + |
| 51 | + for (int j = 0; j < list.size(); j++) { |
| 52 | + if (list.get(j).phoneNumber == phoneNumber) { |
| 53 | + list.get(j).add(); |
| 54 | + break; |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + int maxValue = 0; |
| 60 | + |
| 61 | + for (int i = 0; i < list.size(); i++) { |
| 62 | + if (list.get(i).frequency > maxValue) { |
| 63 | + maxValue = list.get(i).frequency; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + int favouriteNumber = 99999999; |
| 68 | + String name = ""; |
| 69 | + for (int i = 0; i < list.size(); i++) { |
| 70 | + if (list.get(i).frequency == maxValue && favouriteNumber > list.get(i).phoneNumber) { |
| 71 | + favouriteNumber = list.get(i).phoneNumber; |
| 72 | + name = list.get(i).name; |
| 73 | + } |
| 74 | + } |
| 75 | + System.out.println(name); |
| 76 | + } |
| 77 | + |
| 78 | + public static String readLine() throws IOException { |
| 79 | + return in.readLine(); |
| 80 | + } |
| 81 | + |
| 82 | + public static String readString() throws IOException { |
| 83 | + return readLine(); |
| 84 | + } |
| 85 | + |
| 86 | + public static int readInt() throws IOException { |
| 87 | + return Integer.parseInt(readLine()); |
| 88 | + } |
| 89 | + |
| 90 | + public static long readLong() throws IOException { |
| 91 | + return Long.parseLong(readLine()); |
| 92 | + |
| 93 | + } |
| 94 | + public static double readDouble() throws IOException { |
| 95 | + return Double.parseDouble(readLine()); |
| 96 | + } |
| 97 | + |
| 98 | + public static char readCharacter() throws IOException { |
| 99 | + return readLine().charAt(0); |
| 100 | + } |
| 101 | + |
| 102 | + public static String[] readSpaceInput() throws IOException { |
| 103 | + return in.readLine().split(" "); |
| 104 | + } |
| 105 | +} |
0 commit comments