Къде ми е грешката в задача Password reset и защо judge ми дава 75 точки?
Ето моя код: https://pastebin.com/3Wcu5HjE
Това е условието на задачата:
Programming Fundamentals Final Exam 04.04.2020
Problem 1. Password Reset
Yet again you have forgotten your password... Naturally it`s not the first time this has happened. Actually you got so tired of it that you decided to help yourself with a smart solution.
Write a password reset program that performs a series of commands upon a predefined string. First, you will receive a string and afterwards, until the command "Done" is given, you will be receiving strings with commands split by a single space. The commands will be the following:
- TakeOdd
- Takes only the characters at odd indices and concatenates them together to
obtain the new raw password and then prints it.
- Takes only the characters at odd indices and concatenates them together to
- Cut {index} {length}
- Gets the substring with the given length starting from the given index from the password and removes its first occurrence of it, then prints the password on the console.
- The given index and length will always be valid.
- Substitute {substring} {substitute}
- If the raw password contains the given substring, replaces all of its
occurrences with the substitute text given and prints the result. - If it doesn’t, prints "Nothing to replace!"
- If the raw password contains the given substring, replaces all of its
Input
- You will be receiving strings until the "Done" command is given.
Output
- After the "Done" command is received, print:
- "Your password is: {password}"
Constraints
- The indexes from the "Cut {index} {length}" command will always be valid.
Examples
Input |
Output |
Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr TakeOdd Cut 15 3 Substitute :: - Substitute | ^ Done |
icecream::hot::summer icecream::hot::mer icecream-hot-mer Nothing to replace! Your password is: icecream-hot-mer |
Comments |
|
TakeOdd Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr -> icecream::hot::summer We only take the chars at odd indices 1, 3, 5 etc. Cut 15 3 -> icecream::hot::summer -> sum icecream::hot::mer We cut a substring starting at index 15 with length 3, remove it from the raw password and print it. Then, on a new line we print the resulting new raw password. Substitute :: - -> icecream::hot::summer -> icream-hot-summer We replace "::" with "-". Substitute | ^ -> Nothing to replace! "|" is not found anywhere in the raw password. Finally, after receiving the "Done" command, we print the resulting password in the proper format. |
|
Input |
Output |
up8rgoyg3r1atmlmpiunagt!-irs7!1fgulnnnqy TakeOdd Cut 18 2 Substitute ! *** Substitute ? .!. Done |
programming!is!funny programming!is!fun programming***is***fun Nothing to replace! Your password is: programming***is***fun |
JS Input / Output
Input |
Output |
(["Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr", "TakeOdd", "Cut 15 3", "Substitute :: -", "Substitute | ^", "Done"]) |
icecream::hot::summer icecream::hot::mer icecream-hot-mer Nothing to replace! Your password is: icecream-hot-mer |
Comments |
|
TakeOdd Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr -> icecream::hot::summer We only take the chars at odd indices 1, 3, 5 etc. Cut 15 3 -> icecream::hot::summer -> sum icecream::hot::mer We cut a substring starting at index 15 with length 3, remove it from the raw password and print it. Then, on a new line we print the resulting new raw password. Substitute :: - -> icecream::hot::summer -> icream-hot-summer We replace "::" with "-". Substitute | ^ -> Nothing to replace! "|" is not found anywhere in the raw password. Finally, after receiving the "Done" command, we print the resulting password in the proper format. |
|
Input |
Output |
(["up8rgoyg3r1atmlmpiunagt!-irs7!1fgulnnnqy", "TakeOdd", "Cut 18 2", "Substitute ! ***", "Substitute ? .!.", "Done"]) |
programming!is!funny programming!is!fun programming***is***fun Nothing to replace! Your password is: programming***is***fun |
Благодаря за бързите отговори. Помогнахте ми много.
Моля, радвам се.