[Huawei Computer Test Real Questions Python] Remove extra spaces

Question description

Removes excess whitespace from text, but not between paired single quotes. Give the starting and ending subscripts of the keyword, remove excess spaces and refresh the starting and ending subscripts of the keyword.

Conditional constraints:
1. The scenario where the starting and ending position of the keyword is a space is not considered;
2. The beginning and end of the word The subscript is guaranteed to cover a complete word, that is, there will be no extra spaces between the start and end subscript of a coordinate pair;
3. If there are single quotes, the use case ensures that the single quotes are paired Appear;
4. Keywords may be repeated;
5. Text character length length range: [0, 100000];

Enter description

  • The input is a two-line string:

    The first line: the text to be removed from extra spaces. The use case ensures that if there are single quotes, they appear in pairs, and there may be multiple pairs of single quotes.

    The second line: the start and end coordinates of the keywords, separated by commas between keywords, and the start and end positions within the keywords separated by a single space.

Output description

  • The output is a two-line string:

    The first line: the text after removing excess spaces
    The second line: the starting and ending coordinates of the keyword after removing excess spaces, output in array mode.

Reference example

Example 1

enter

Life is painting a  picture, not doing 'a  sum'.
8 15,20 26,43 45


Output    

Life is painting a picture, not doing 'a  sum'.
[8, 15][1

Guess you like

Origin blog.csdn.net/forest_long/article/details/135004584