您的位置:首页 > 产品设计 > UI/UE

uva 10420 - List of Conquests

2014-04-15 14:35 471 查看
import java.io.*;
import java.math.BigInteger;
import java.util.*;

class problem{
void solver() throws IOException{
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int i=0;i<n;i++){
String tmp[] = scan.nextLine().split("\\s+");
if(!map.containsKey(tmp[0])){
map.put(tmp[0], 1);
}else{
int val = map.get(tmp[0]);
map.put(tmp[0], val+1);
}
}
Set<String> t = map.keySet();
List<String> list = new ArrayList<String>(t);
Collections.sort(list);
for(int i=0;i<list.size();i++){
System.out.println(list.get(i)+" "+map.get(list.get(i)));
}
}
}
public class Main {
public static void main (String [] args) throws Exception {
problem p = new problem();
p.solver();
}
}


好吧我已经开始做这种题了。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: