#281. 字符串截取与条件判断
字符串截取与条件判断
Substring Extraction
Background
Congcong is currently learning about string operations. He encountered a problem that requires extracting a substring of a specific length from a given string.
Problem Description
Given a string and an index, return a string of length starting at the given index. If the index is too big or too small to define a string of length , use the first characters of the string. The string length will be at least .
Input Format
The input consists of two lines.
The first line contains a string . The second line contains an integer , representing the starting index.
Output Format
Output a string, which is the extracted substring.
Sample
java"
"ja"
java"
"va"
java"
"ja"
Sample Explanation
- For Sample 1, assuming the input string is "java" and the index is . The substring of length starting at index is "ja".
- For Sample 2, assuming the input string is "java" and the index is . The substring of length starting at index is "va".
- For Sample 3, assuming the input string is "java" and the index is or . Since the index is too small or too large to define a substring of length , the first characters of the string, "ja\