Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

string winner ( string erica, string bob ) { int ericaScore = 0 ; / / Initialize Erica's score to 0 int bobScore = 0

string winner(string erica, string bob){
int ericaScore =0; // Initialize Erica's score to 0
int bobScore =0; // Initialize Bob's score to 0
int n = erica.length(); // Get the length of the input strings
// Loop through each day's problem
for (int i =0; i < n; i++){
// Check the difficulty of the problem Erica solved on that day
if (erica[i]=='E'){
ericaScore +=1; // Add 1 point for an easy problem
} else if (erica[i]=='M'){
ericaScore +=3; // Add 3 points for a medium problem
} else if (erica[i]=='H'){
ericaScore +=5; // Add 5 points for a hard problem
}
// Repeat the same steps for the problem Bob solved on that day
if (bob[i]=='E'){
bobScore +=1;
} else if (bob[i]=='M'){
bobScore +=3;
} else if (bob[i]=='H'){
bobScore +=5;
}
}
// 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

Briefly explain Chebyshevs theorem and its applications.

Answered: 1 week ago

Question

Which persons umbrella is this?

Answered: 1 week ago

Question

Have you given John and Nancy a list of parts?

Answered: 1 week ago