Poj 2403 Hay Points(Map)

一、题目大意

        实现一个工资计算系统。工资的计算规则是:首先,给定一些关键字和对应的价值,这个相对于字典。然后给出的是求职者的描述,如果这个描述中包含关键字则加上对应的价值,总得价值就是这个求职者的工资。

二、题解

        实现很简单,把关键字和价值用一个Map先存起来,然后依次读取描述,关键字相同则加上价值量。

三、java代码

import java.util.HashMap;
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
	 Scanner sc=new Scanner(System.in);
	 int m,n,i,num;
	 String s;
	 m=sc.nextInt();
	 n=sc.nextInt();
     HashMap<String,Integer> map=new HashMap<String,Integer>();
     for(i=0;i<m;i++){
    	 map.put(sc.next(),sc.nextInt());
     }
     while(n--!=0){
    	 num=0;
    	 while(!((s=sc.next()).equals("."))){
    		 if(map.containsKey(s))
    			 num+=map.get(s);
    	 }
    	 System.out.println(num);
     }
  } 
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2013-08-12 22:52  InkGenius  阅读(154)  评论(0编辑  收藏  举报