#K94057. Safe String Truncation with Tolerance
Safe String Truncation with Tolerance
Safe String Truncation with Tolerance
Given a string ( s ), an integer ( L ) (limit), and an integer ( T ) (tolerance), your task is to truncate the string without splitting any word. Words are separated by spaces. You must include as many words as possible such that the total length does not exceed ( L ). However, if adding the next word causes the length to exceed ( L ) but does not exceed ( L+T ), then include that word and stop. Otherwise, do not include that word. If the first word is longer than ( L ), output an empty string.
Examples:
- For input: "This is an example of a string", ( L = 12 ), ( T = 5 ), the output is "This is an".
- For input: "Hello world", ( L = 11 ), ( T = 0 ), the output is "Hello world".
- For input: "Supercalifragilisticexpialidocious", ( L = 5 ), ( T = 1 ), the output is "".
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- A non-empty string ( s ).
- An integer ( L ) representing the limit.
- An integer ( T ) representing the tolerance.
outputFormat
Output the truncated string to standard output (stdout).## sample
This is an example of a string
12
5
This is an