hdu 1263 java做法

import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
class Node{
TreeMap hashMap;
public Node() {
hashMap = new TreeMap();
}
public void add(String name, Integer number) {
        Integer n = hashMap.get(name);
        if (n==null) {
hashMap.put(name, number);
}else {
hashMap.put(name, n+number);
}
}
public void to() {
        Set n = hashMap.keySet();
         Iterator k = n.iterator();
         while (k.hasNext()) {
String a = k.next();
Integer h = hashMap.get(a);
System.out.println("   |----"+a+"("+h+")");
}
}
}
public class Main {
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in );
         int n = sc.nextInt();
         for (int i = 0; i < n; i++) {
int m = sc.nextInt();
TreeMap h = new TreeMap();
for (int j = 0; j < m; j++) {
String name = sc.next();
String place = sc.next();
Integer number = sc.nextInt();
Node g = h.get(place);
if (g==null) {
Node node = new Node();
node.add(name,number);
h.put(place, node);
}else {
g.add(name, number);
h.put(place, g);
}
}
Set k = h.keySet();
Iterator y = k.iterator();
while (y.hasNext()) {
String key = y.next();
Node a = h.get(key);
System.out.println(key);
a.to();
}
if(i!=n-1)
System.out.println();
}
}
}

你可能感兴趣的:(hdu 1263 java做法)