import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m = "";
int cases=Integer.parseInt(br.readLine());
for(int j=0;j<cases;j++){
if(j>0)
sb.append("\n");
br.readLine();
HashMap<String,String> hm=new HashMap<String, String>();
int n=Integer.parseInt(br.readLine().trim());
int[]arr=new int[n];
String[]str=new String[n];
for(int i=0;i<n;i++) {
m=br.readLine().trim();
hm.put(m, br.readLine().trim());
str[i]=m;
}
Arrays.sort(str);
n=Integer.parseInt(br.readLine().trim());
int max=0,indOfMax=0;
for(int i=0;i<n;i++) {
int ind=Arrays.binarySearch(str, br.readLine().trim());
if(ind>-1){
arr[ind]++;
if(arr[ind]>max){
max=arr[ind];
indOfMax=ind;
}
}
}
int counter=0;
for(int i=0;i<arr.length;i++){
if(arr[i]==max){
counter++;
}
}
if(counter>1){
sb.append("tie\n");
}else{
sb.append(hm.get(str[indOfMax])).append("\n");
}
}
System.out.print(sb);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m = "";
int cases=Integer.parseInt(br.readLine());
for(int j=0;j<cases;j++){
if(j>0)
sb.append("\n");
br.readLine();
HashMap<String,String> hm=new HashMap<String, String>();
int n=Integer.parseInt(br.readLine().trim());
int[]arr=new int[n];
String[]str=new String[n];
for(int i=0;i<n;i++) {
m=br.readLine().trim();
hm.put(m, br.readLine().trim());
str[i]=m;
}
Arrays.sort(str);
n=Integer.parseInt(br.readLine().trim());
int max=0,indOfMax=0;
for(int i=0;i<n;i++) {
int ind=Arrays.binarySearch(str, br.readLine().trim());
if(ind>-1){
arr[ind]++;
if(arr[ind]>max){
max=arr[ind];
indOfMax=ind;
}
}
}
int counter=0;
for(int i=0;i<arr.length;i++){
if(arr[i]==max){
counter++;
}
}
if(counter>1){
sb.append("tie\n");
}else{
sb.append(hm.get(str[indOfMax])).append("\n");
}
}
System.out.print(sb);
}
}
No comments:
Post a Comment