#C7083. Shortest Distance to a Character
Shortest Distance to a Character
Shortest Distance to a Character
Given a string \(S\) and a character \(C\), your task is to compute an array of integers where each element represents the shortest distance from the corresponding character in \(S\) to the character \(C\). It is guaranteed that \(C\) appears at least once in \(S\).
The distance between positions \(i\) and \(j\) is defined as \(|i - j|\). For example, if \(S = \texttt{loveleetcode}\) and \(C = \texttt{e}\), then the expected output is [3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0]
because the character 'e' appears in positions where the minimum distances are as given.
Solve this problem by processing input from standard input (stdin) and producing output to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line contains the string \(S\) consisting of lowercase letters.
- The second line contains the character \(C\) (a single lowercase letter that is guaranteed to appear in \(S\)).
Note: There is exactly one test case per execution.
outputFormat
Output a single line with \(n\) space-separated integers, where \(n\) is the length of \(S\). The \(i\)-th integer should represent the shortest distance from \(S[i]\) to any occurrence of the character \(C\).
## sampleloveleetcode
e
3 2 1 0 1 0 0 1 2 2 1 0