#K56897. Minimum Distance From Start
Minimum Distance From Start
Minimum Distance From Start
Given a string s
and a character c
, your task is to find the minimum distance from the beginning of the string s
to the first occurrence of c
. The distance is measured as the number of characters between the beginning (position 0) and the position of c
in the string. Mathematically, if the index of the first occurrence of c
is \( i \), then the distance is \( i \). If the character c
is not present in s
, output -1
.
Input Format: The input consists of two lines. The first line contains the string s
and the second line contains the character c
.
Output Format: Output a single integer which is the minimum distance from the start of the string to the first occurrence of c
. If the character c
does not occur in s
, output -1
.
For example, if s = "hello"
and c = 'e'
, then the output is 1
because 'e' appears at index 1. If s = "abcde"
and c = 'z'
, then the output is -1
because 'z' does not occur in the string.
inputFormat
The input consists of two lines:
- The first line contains the string
s
. - The second line contains a single character
c
.
outputFormat
Output a single integer representing the first index of c
in s
, or -1
if c
does not appear in s
.
hello
e
1