Connection Status:
Competition Arena > DietPlan
SRM 372 · 2007-10-17 · by connect4 · String Parsing
Class Name: DietPlan
Return Type: String
Method Name: chooseDinner
Arg Types: (string, string, string)
Problem Statement

Problem Statement

The doctor has given you your diet, in which each character corresponds to some food that you should eat. You also know what you have eaten for breakfast and lunch, in which each character corresponds to a type of food that you have already eaten that day. You have decided that you will eat all of the remaining food in your diet during dinner, and you want to return that as a String (sorted in alphabetical order). If you have cheated in anyway (either by eating too much of one type of food, or by eating some food that is not in the dietPlan), you should return the String "CHEATER" (quotes for clarity).

Constraints

  • diet will contain between 0 and 26 characters, inclusive.
  • Each character in diet will be an uppercase letter ('A'-'Z').
  • There will be no duplicate characters in diet.
  • breakfast will contain between 0 and 26 characters, inclusive.
  • Each character in breakfast will be an uppercase letter ('A'-'Z').
  • lunch will contain between 0 and 26 characters, inclusive.
  • Each character in lunch will be an uppercase letter ('A'-'Z').
  • There will be no duplicate characters in breakfast.
  • There will be no duplicate characters in lunch.
  • No character will appear in both breakfast and lunch.
Examples
0)
"ABCD"
"AB"
"C"
Returns: "D"

Here, you have eaten most of your food for the day. So, you can only eat a single 'D' for dinner.

1)
"ABEDCS"
""
""
Returns: "ABCDES"

Here you've saved all of your food for dinner.

2)
"EDSMB"
"MSD"
"A"
Returns: "CHEATER"

You cheated at lunch time by eating an 'A'!

3)
""
""
""
Returns: ""
4)
"IWANTSODER"
"SOW"
"RAT"
Returns: "DEIN"

Submissions are judged against all 79 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class DietPlan with a public method string chooseDinner(string diet, string breakfast, string lunch) · 79 test cases · 2 s / 256 MB per case

Submitting as anonymous