nyoj 904 hashmap

这个题目是个水题目,现在我只管做出来,效率不考虑了。

 

题目链接:

http://acm.nyist.net/JudgeOnline/problem.php?pid=904image

我用hashmap 很爽,很简单,但效率很低,别人有的是用二分查找,不管了,

package nyoj904;

import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scn=new Scanner(System.in);
        int len=scn.nextInt();
        while(len-->0)
        {
            HashMap<Integer,String> hash=new HashMap<Integer,String>();
            int m=scn.nextInt();
            int n=scn.nextInt();
            while(m-->0)
            {
                String name=scn.next();
                int score=scn.nextInt();
                if(!hash.containsKey(score))
                        {
                    hash.put(score, name);
                    
                        }    
                
                
                
            }
            while(n-->0)
            {
                System.out.println(hash.get(scn.nextInt()));
                
            }
            
            
        }

    }

}
posted @ 2014-06-23 18:41  hansongjiang8  阅读(83)  评论(0编辑  收藏  举报