LoveCalculator
SRM 427 · 2008-11-25 · by rasto6sk
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
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.
"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.
"JANE"
{"THOMAS","MICHAEL","INDY","LIU"}
Returns: "INDY"
The probability of love is 0 percent for all the boys. Among them, INDY comes first alphabetically.
"LILLY"
{"PIERRE"}
Returns: "PIERRE"
"MERYLOV"
{"JOHN","DAVE","STEVE","JOHN","DAVE"}
Returns: "DAVE"
"ANN"
{"HENRY","TIM"}
Returns: "HENRY"
Submissions are judged against all 78 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LoveCalculator with a public method string findBoy(string girl, vector<string> boys) · 78 test cases · 2 s / 256 MB per case