#K33092. Find Substring Index
Find Substring Index
Find Substring Index
The problem is to find the first occurrence of a given substring in a main string. You are given two strings as input. The first string is the main string and the second string is the substring you must search for. If the substring exists in the main string, output the index (0-indexed) of the first occurrence. If it does not exist, output -1. Note that if the substring is empty, the answer is always 0.
For example, given the main string "hello world" and substring "world", the output should be 6
because the substring "world" starts at index 6.
This problem requires you to read inputs from stdin and output the result to stdout.
inputFormat
The input consists of exactly two lines. The first line contains the main string s and the second line contains the substring sub.
If the substring is empty, the corresponding line will be empty.
outputFormat
Output a single integer which is the first index of occurrence of the substring in the main string. If the substring is not found, output -1.
## samplehello world
world
6