Choosing a Team Name
InterviewTime limit2sMemory limit128 MB
Count letters L,O,V,E across a fixed name plus each candidate string, compute a formula mod 100, and print the candidate with the highest value, breaking ties by lexicographic order.
- Level
Easy2 of 10
- Topics
- String, Implementation, Brute force
- Solved
- No attempts yet
Problem
Yeondoo is choosing a team name for a programming contest. Because she believes in superstition, she received a formula from Ihwan for calculating a team's chance of winning. She wants to use the formula to pick the candidate team name with the highest chance of winning.
The formula uses four variables: L, O, V, and E. Each variable is the number of times that letter appears after combining Yeondoo's English name with the team name.
L: the number ofLcharacters in Yeondoo's English name and the team nameO: the number ofOcharacters in Yeondoo's English name and the team nameV: the number ofVcharacters in Yeondoo's English name and the team nameE: the number ofEcharacters in Yeondoo's English name and the team name
Substitute these four values into the following expression to get the winning chance for that team name.
((L + O) × (L + V) × (L + E) × (O + V) × (O + E) × (V + E)) mod 100
Given Yeondoo's English name and N candidate team names, output the team name with the highest winning chance. If several candidates have the same highest chance, choose the lexicographically smallest team name.
Input
The first line contains Yeondoo's English name. The second line contains the number of candidate team names, N. Each of the next N lines contains one candidate team name.
Yeondoo's English name and every team name each have length between 1 and 20, inclusive, and consist only of uppercase English letters. N is a positive integer no greater than 50.
Output
Print the team name with the highest winning chance on the first line.