Hay Points
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3255 | Accepted: 2112 |
Description
Each
employee of a bureaucracy has a job description - a few paragraphs that
describe the responsibilities of the job. The employee's job
description, combined with other factors, such as seniority, is used to
determine his or her salary.
The Hay Point system frees the Human Resources department from having to make an intelligent judgement as to the value of the employee; the job description is merely scanned for words and phrases that indicate responsibility. In particular, job descriptions that indicate control over a large budget or management over a large number of people yield high Hay Point scores.
You are to implement a simplified Hay Point system. You will be given a Hay Point dictionary and a number of job descriptions. For each job description you are to compute the salary associated with the job, according to the system.
The Hay Point system frees the Human Resources department from having to make an intelligent judgement as to the value of the employee; the job description is merely scanned for words and phrases that indicate responsibility. In particular, job descriptions that indicate control over a large budget or management over a large number of people yield high Hay Point scores.
You are to implement a simplified Hay Point system. You will be given a Hay Point dictionary and a number of job descriptions. For each job description you are to compute the salary associated with the job, according to the system.
Input
The
first line of input contains 2 positive integers: m <= 1000, the
number of words in the Hay Point dictionary, and n <= 100, the
number of job descriptions. m lines follow; each contains a word (a
string of up to 16 lower-case letters) and a dollar value (a integer
number between 0 and 1,000,000). Following the dictionary are the n job
descriptions. Each job description consists of one or more lines of
text; for your convenience the text has been converted to lower case
and has no characters other than letters, numbers, and spaces. Each job
description is terminated by a line containing a period.
Output
For
each job description, output the corresponding salary computed as the
sum of the Hay Point values for all words that appear in the
description. Words that do not appear in the dictionary have a value of
0.
Sample Input
7 2 administer 100000 spending 200000 manage 50000 responsibility 25000 expertise 100 skill 50 money 75000 the incumbent will administer the spending of kindergarden milk money and exercise responsibility for making change he or she will share responsibility for the task of managing the money with the assistant whose skill and expertise shall ensure the successful spending exercise . this individual must have the skill to perform a heart transplant and expertise in rocket science .
Sample Output
700150 150
此题需要注意:
1.可能出现多个单词重复计数,因此最好对字符串进行遍历
2.注意前后的空格,以及单词中间的多个空格。
import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); String[] fLine = cin.nextLine().split(" "); int kwNum = Integer.valueOf(fLine[0]).intValue(); int descNum = Integer.valueOf(fLine[1]).intValue(); HashMap hm = new HashMap(); for(int i = 0; i < kwNum; i++) { String[] str = cin.nextLine().split(" "); hm.put(str[0], str[1]); } for(int i = 0; i < descNum; i++) { StringBuffer sb = new StringBuffer(); String job = null; int salary = 0; while(true) { job = cin.nextLine(); if(job.equals(".")) break; else sb.append(job + " "); } job = sb.toString().trim(); if(job.length() == 0) { System.out.println("0"); continue; } int eIndex = 0; String word = null; while(true) { eIndex = job.indexOf(" "); if(eIndex == -1 || eIndex == 0) { if(hm.containsKey(job)) salary += Integer.valueOf((String)hm.get(job)); break; } word = job.substring(0, eIndex); job = job.substring(eIndex + 1).trim(); if(hm.containsKey(word)) salary += Integer.valueOf((String)hm.get(word)); } System.out.println(salary); } } }
发表评论
-
POJ ACM习题【No.2328】
2009-07-05 19:43 894Guessing Game Time ... -
POJ ACM习题【No.3157】
2009-04-26 23:54 1629Java vs C++ Time Lim ... -
POJ ACM习题【No.2924】
2009-04-26 11:52 917Gauß in Elementary School ... -
POJ ACM习题【No.3176】
2009-04-26 10:53 1040Cow Bowling Time Lim ... -
POJ ACM习题【No.3173】
2009-04-25 23:30 898Parkside's Triangle ... -
POJ ACM习题【No.2845】
2009-04-25 22:25 120601000001 Time Limit: ... -
POJ ACM习题【No.2140】
2009-04-25 21:26 930Herd Sums Time Limit ... -
POJ ACM习题【No.1969】
2009-04-25 20:59 854Count on Canton Time ... -
POJ ACM习题【No.2840】
2009-04-25 19:24 1000Big Clock Time Limit ... -
POJ ACM习题【No.2521】
2009-04-24 22:41 842How much did the businessman l ... -
POJ ACM习题【No.1326】
2009-04-24 22:14 1004Mileage Bank Time Li ... -
POJ ACM习题【No.3325】
2009-04-24 21:15 1084ICPC Score Totalizer Software ... -
POJ ACM习题【No.2756】
2009-04-24 20:28 769Autumn is a Genius T ... -
POJ ACM习题【No.3062】
2009-04-24 20:10 802Celebrity jeopardy ... -
POJ ACM习题【No.1547】
2009-04-23 20:03 766Clay Bully Time Limi ... -
POJ ACM习题【No.1552】
2009-04-23 19:39 745Doubles Time Limit: ... -
POJ ACM习题【No.1007】
2009-04-23 19:24 844DNA Sorting Time Lim ... -
POJ ACM习题【No.1565】
2009-04-22 22:40 836Skew Binary Time Lim ... -
POJ ACM习题【No.1862】
2009-04-22 20:12 693Stripies Time Limit: ... -
POJ ACM习题【No.3224】
2009-04-22 19:57 737Lab杯 Time Limit: 1 ...
相关推荐
方便大家有针对性地联系 祝大家AC愉快~
pojACM题目分类,便于各类型同学分别做题有所参考
相信大家在做poj上的题目的时候如果没有分类的话很迷茫吧....这里有一份目前比较全面的poj题目分类..
02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ...
poj 2403 Hay Points.md
acm数据结构总结.doc acm数据结构总结.doc
poj acm题解,包括绝大部分poj题目的题解,可以供acm爱好者学习研究
本文件是ACM里的一些题目的源码、原题和习题的分析及详细解答。欢迎各位下载
http://acm.pku.edu.cn/JudgeOnline/ acm的AC解题报告
POJ ACM 1015 Jury Compromise 两种解法 解题报告
西工大C语言POJ习题答案.docx
PKU 、POJ ACM/ICPC300多题的代码,还有各种典型问题的分类代码
poj 2007 Scrambled Polygon.md
poj 3183 Stump Removal.md
poj 1984 Navigation Nightmare.md
poj 2430 Lazy Cows.md
poj 2900 Griddy Hobby.md
poj 3435 Sudoku Checker.md
poj 2386 Lake Counting.md
poj 2668 Defending Castle.md