Answered step by step
Verified Expert Solution
Question
1 Approved Answer
string winner ( string erica, string bob ) { int ericaScore = 0 ; / / Initialize Erica's score to 0 int bobScore = 0
string winnerstring erica, string bob
int ericaScore ; Initialize Erica's score to
int bobScore ; Initialize Bob's score to
int n erica.length; Get the length of the input strings
Loop through each day's problem
for int i ; i n; i
Check the difficulty of the problem Erica solved on that day
if ericaiE
ericaScore ; Add point for an easy problem
else if ericaiM
ericaScore ; Add points for a medium problem
else if ericaiH
ericaScore ; Add points for a hard problem
Repeat the same steps for the problem Bob solved on that day
if bobiE
bobScore ;
else if bobiM
bobScore ;
else if bobiH
bobScore ;
Compare scores to determine the winner
if ericaScore bobScore
return "Erica"; Erica wins
else if bobScore ericaScore
return "Bob"; Bob wins
else
return "Tie"; It's a tie
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started