TopCoder problem "AnswerEvaluation" used in TCHS SRM 24 (Division I Level One)



Problem Statement

    

Your teacher proposes the following quick method of evaluating the correctness of the answer to an exam question. She writes down several distinct keywords she expects to find in a correct answer. Each keyword has a score associated with it. She then searches for each keyword in the student?s answer. If she finds it, she adds the score of the keyword to the student's score. If she finds the keyword multiple times, she only adds its score once.

You are given a String[] keywords and a int[] scores. The ith element of keywords contains the ith keyword. The ith element of scores gives the score associated with the ith keyword. You are also given a String answer with the student's answer. answer will be a single-space delimited list of words. Return the final score the student will receive for his answer.

 

Definition

    
Class:AnswerEvaluation
Method:getScore
Parameters:String[], int[], String
Returns:int
Method signature:int getScore(String[] keywords, int[] scores, String answer)
(be sure your method is public)
    
 

Constraints

-keywords will contain between 1 and 25 elements, inclusive.
-Each element of keywords will contain between 1 and 50 characters, inclusive.
-Each element of keywords will contain only lowercase letters ('a'-'z').
-The strings in keywords will be distinct.
-scores will contain the same number of elements as keywords.
-Each element of scores will be between 1 and 1000, inclusive.
-answer will contain between 1 and 50 characters, inclusive.
-answer will contain only lowercase letters ('a'-'z') and spaces, and will not contain leading/trailing spaces or double spaces.
 

Examples

0)
    
{"red", "fox", "lazy", "dogs"}
{25, 25, 25, 25}
"the quick brown fox jumped over the lazy dog"
Returns: 50
We can find the words "fox" and "lazy" in the student's answer, but not the other two words. The final score will be 25 + 25 = 50.
1)
    
{"red", "fox", "lazy", "dogs"}
{25, 25, 25, 25}
"highschool matches are nice"
Returns: 0
This answer is totally unrelated with the question. We can not find any of the keywords in it.
2)
    
{"red", "fox", "lazy", "dogs"}
{1, 2, 3, 4}
"lazy lazy lazy lazy"
Returns: 3
The word "lazy" is present in the answer multiple times, but we should count its contribution to the final score once.
3)
    
{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
 "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"}
{1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000,
 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000}
"a b c d e f g h i j k l m n o p q r s t u v x y z"
Returns: 25000

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7272

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10076&pm=7272

Writer:

_efer_

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration, String Manipulation, String Parsing