SafeManipulation problem from Arrays More Exercises
Здравейте. Трябва ми малко помощ за тази задача:
Ето го и моят код...пропускам някой case, но не ми идват повече идеи:
https://pastebin.com/QwPhG7GL
Problem 1.Safe Manipulation
Now we need to make our program safer and more user-friendly. Make the program print “Invalid input!” if we try to replace an element at a non-existent index or an invalid command is written on the console. Also make the program work until the command “END” is given as an input.
Input
- On the first line, you will receive the string array
- On the next lines until you receive “END” – you will receive commands
Output
At the end, print the array in the following format:
{1st element}, {2nd element}, {3rd element} … {nth element}
Constraints
- Only a single whitespace will be used for the separator.
- n will be an integer in the interval [1…100]
Examples
Input |
Output |
one one one two three four five Distinct Reverse Replace 7 Hello Replace -5 Hello Replace 0 Hello END |
Invalid input! Invalid input! Hello, four, three, two, one |
Input |
Output |
Alpha Bravo Charlie Delta Echo Foxtrot Distinct Reverse Replace 0 Charlie Reverse Replace 1 Charlie Distinct Replace 4 Charlie END |
Invalid input! Invalid input! Alpha, Charlie, Delta, Echo |