编程语言:Java
题目:
题解:不超时需要用技巧。
结果:AC
import java.io.*;
import java.util.*;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) throws IOException {
in.nextToken();
int n= (int) in.nval;
Map<String,Integer> map=new LinkedHashMap<>();
String t;
for(int i=0;i<n;i++){
in.nextToken();
t=in.nval+"";
if(map.containsKey(t))
map.put(t,(int)map.get(t)+1);
else
map.put(t,1);
in.nextToken();
t=in.nval+"";
if(map.containsKey(t))
map.put(t,(int)map.get(t)+1);
else
map.put(t,1);
}
int sum=0;
int num=0;
String res="";
Iterator<Map.Entry<String, Integer>> entries = map.entrySet().iterator();
while(entries.hasNext()){
Map.Entry<String, Integer> entry = entries.next();
if(entry.getValue()>sum){
res=entry.getKey();
num=1;
sum=entry.getValue();
}else if(entry.getValue()==sum){
num++;
if(res.compareTo(entry.getKey())>0){
res=entry.getKey();
}
}
}
res=res.substring(0,1)+res.substring(2,12);
if(num==1){
out.println(res+" "+sum);
}else{
out.println(res+" "+sum+" "+num);
}
out.flush();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)