#C13551. Shortest Distance to Character
Shortest Distance to Character
Shortest Distance to Character
Given a string \( s \) and a character \( c \), compute for each index \( i \) the minimum distance to any occurrence of \( c \) in \( s \). The distance for an index \( i \) is defined as \( |i - j| \) where \( s[j] = c \) and \( j \) is any valid index in \( s \). If \( c \) does not appear in \( s \), output \(-1\) for every position.
Detailed Explanation:
- If character \( c \) is found in \( s \), then for every index \( i \) (0-indexed), you must determine \( \min_{j: s[j]=c} |i - j| \).
- If \( c \) does not appear, every value in the result should be \(-1\).
Note: The answer list should be printed as space-separated integers on one line.
inputFormat
The input is provided via stdin and consists of two lines:
- The first line contains the string \( s \).
- The second line contains the character \( c \).
outputFormat
Output a single line containing the list of distances for each index in \( s \). The distances should be printed as space-separated integers. If \( c \) does not occur in \( s \), output \(-1\) for every index.
## samplea
a
0