TreeMap 嵌套

点击打开链接


水果

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6965    Accepted Submission(s): 2733


Problem Description
夏天来了~~好开心啊,呵呵,好多好多水果~~
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
 

Input
第一行正整数N(0<N<=10)表示有N组测试数据.
每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.
 

Output
对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序.
两组测试数据之间有一个空行.最后一组测试数据之后没有空行.
 

Sample Input
  
  
1 5 apple shandong 3 pineapple guangdong 1 sugarcane guangdong 1 pineapple guangdong 3 pineapple guangdong 1
 

Sample Output
  
  
guangdong |----pineapple(5) |----sugarcane(1) shandong |----apple(3)
 
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;


public class Main {
	
	public static void main(String[] args){
		new Task().solve();
	}
}

class Task{
	InputReader in = new InputReader(System.in) ;  
    PrintWriter out = new PrintWriter(System.out) ;  


	void solve(){
		int n = in.nextInt() ;
		int k ;
		for( k = 1 ; k <= n ; k++){
			int m = in.nextInt() ;
			Map<String, TreeMap<String, Integer>> outmap = new TreeMap<String, TreeMap<String, Integer> >() ;
			while(m-- >0){
				String name = in.next() ;
				String city = in.next() ;
				int count = in.nextInt() ;
				if(! outmap.containsKey(city) ){
					outmap.put(city, new TreeMap<String, Integer>()) ;
				}
				Integer cc = outmap.get(city).get(name) ;
				if(cc == null){
					outmap.get(city).put(name, count) ;
				}else{
					outmap.get(city).put(name, count + cc) ;
				}
				
			}
			if(k!=1){
				out.println();
			}
			for(Map.Entry<String, TreeMap<String, Integer> > mm : outmap.entrySet() ){
				String s = mm.getKey() ;
				out.println(s);
				Map<String , Integer> inmap = mm.getValue() ;
				for(Map.Entry<String , Integer> e : inmap.entrySet() ){
					out.println("   |----" + e.getKey() + "(" + e.getValue() + ")");
				}
				
			}
			//out.flush();
			
			
			
		}
		out.flush();
	}

}

class InputReader {  
    public BufferedReader reader;  
    public StringTokenizer tokenizer;  
  
    public InputReader(InputStream stream) {  
        reader = new BufferedReader(new InputStreamReader(stream), 32768);  
        tokenizer = new StringTokenizer("");  
    }  
  
    private void eat(String s) {  
        tokenizer = new StringTokenizer(s);  
    }  
  
    public String nextLine() {  
        try {  
            return reader.readLine();  
        } catch (Exception e) {  
            return null;  
        }  
    }  
  
    public boolean hasNext() {  
        while (!tokenizer.hasMoreTokens()) {  
            String s = nextLine();  
            if (s == null)  
                return false;  
            eat(s);  
        }  
        return true;  
    }  
  
    public String next() {  
        hasNext();  
        return tokenizer.nextToken();  
    }  
  
    public int nextInt() {  
        return Integer.parseInt(next());  
    }  
  
    public long nextLong() {  
        return Long.parseLong(next());  
    }  
  
    public double nextDouble() {  
        return Double.parseDouble(next());  
    }  
  
    public BigInteger nextBigInteger() {  
        return new BigInteger(next());  
    }  
  
}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值