TopCoder problem "LoveCalculator" used in SRM 427 (Division II Level One)



Problem Statement

    

A girl would like to go out with one of her favorite boys, but she does not know which one to choose. Fortunately, she has a Love Calculator which can calculate the probability of love between two people. Love Calculator takes two people's names and uses the following algorithm to calculate the probability of love between them:



L := the total number of occurrences of the letter 'L' in both names.

O := the total number of occurrences of the letter 'O' in both names.

V := the total number of occurrences of the letter 'V' in both names.

E := the total number of occurrences of the letter 'E' in both names.



The percent probability of love is equal to ((L+O)*(L+V)*(L+E)*(O+V)*(O+E)*(V+E))%100, where % is the modulo operator. You are given a String girl containing the girl's name, and a String[] boys containing her favorite boys' names. Return the name of the boy with which the girl has the highest probability of love. If there is more than one such boy, return the one among them that comes earliest alphabetically.
 

Definition

    
Class:LoveCalculator
Method:findBoy
Parameters:String, String[]
Returns:String
Method signature:String findBoy(String girl, String[] boys)
(be sure your method is public)
    
 

Constraints

-girl will contain between 1 and 20 uppercase letters ('A'-'Z'), inclusive.
-boys will contain between 1 and 50 elements, inclusive.
-Each element of boys will contain between 1 and 20 uppercase letters ('A'-'Z'), inclusive.
 

Examples

0)
    
"LOVE"
{"JACOB","FRANK","DANO"}
Returns: "FRANK"
The highest probability is 64 percent, and it is achieved with FRANK. The probabilities for JACOB and DANO are both 16 percent.
1)
    
"JANE"
{"THOMAS","MICHAEL","INDY","LIU"}
Returns: "INDY"
The probability of love is 0 percent for all the boys. Among them, INDY comes first alphabetically.
2)
    
"LILLY"
{"PIERRE"}
Returns: "PIERRE"
3)
    
"MERYLOV"
{"JOHN","DAVE","STEVE","JOHN","DAVE"}
Returns: "DAVE"
4)
    
"LLOL"
{"BVERON","CVERON","AVERON","DVERON"}
Returns: "AVERON"
5)
    
"VELYLEOCEVE"
{"YVXHOVE","LCOKO","OGWSJVEVEDLE","WGFVSJEL","VLOLUVCBLLQVESWHEEKC"}
Returns: "VLOLUVCBLLQVESWHEEKC"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13518&pm=10046

Writer:

rasto6sk

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Simple Search, Iteration, String Manipulation