#281. 字符串截取与条件判断

    ID: 281 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatString-1gesp3字符串条件结构

字符串截取与条件判断

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 22 starting at the given index. If the index is too big or too small to define a string of length 22, use the first 22 characters of the string. The string length will be at least 22.

Input Format

The input consists of two lines.

The first line contains a string SS. The second line contains an integer idxidx, 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 00. The substring of length 22 starting at index 00 is "ja".
  • For Sample 2, assuming the input string is "java" and the index is 22. The substring of length 22 starting at index 22 is "va".
  • For Sample 3, assuming the input string is "java" and the index is 1-1 or 33. Since the index is too small or too large to define a substring of length 22, the first 22 characters of the string, "ja\