[Programming Fundamentals] 2.Placeholders - Strings and Text Processing
Здравейте колеги,
Judge ми дава 60/100. Провалените тестове са ми Runtime Error-и. Намерих различни входове, които чупят логиката на решението, но никой от тях не ми гърми задачата. Някой знае ли при какъв вход гърми?
решение - https://pastebin.com/SXjB2SgY
2. Placeholders
Placeholders in C# are really comfortable for use, right? How about you implement them to see just how easy they are.
Input
You will be given input lines containing a string with placeholders, i.e. “This is {0}. And that is {1}.”.
The input lines will be in the following format:
{string} -> {element}, {element2}
You should replace the placeholders in the string with the elements given after the “ -> ” delimiter. The elements are separated by “, ”. Each element has an index, so you must give them the right order. The first given element goes where the 0 is, the second to the 1, and so on…
Output
Print each string with its replaced placeholders, right after you’ve read it, and before reading the next one.
The input ends when you receive the command “end”.
Examples
Input |
Output |
I have a {0} and a {1} -> car, house Cool, and I have a {0}. -> yacht Darn... You beat me {0} {1} -> with, this end |
I have a car and a house Cool, and I have a yacht. Darn... You beat me with this |
This is {2} {1} {0}. -> ment, I, what And this is what you ment. -> nothing end |
This is what I ment. And this is what you ment. |
Hints
- Since the sentences hold spaces, you cannot split the sentence and the values by space.
There should be some functionality in C#, which removes the border spaces from a string, if you split it by
“->”, though. - You might have to split the sentence and the values first, and then the values, because their delimiter contains a space.