#276. 字符串首尾字符提取
字符串首尾字符提取
First or Last Character
Background
Congcong is learning string operations and encountered a simple but interesting problem.
Problem Description
Given a string S and a boolean flag B. If the boolean flag B is true, return the first character of string S; otherwise (if B is false), return the last character of string S. The string S is guaranteed to be non-empty.
Input Format
Input is given from Standard Input in the following format.
input_line(A string containing the original stringSand a boolean flag. The format ofinput_lineisS" B, whereSis the original string andBis the boolean flag, with"tru"representing true and"fals"representing false.)
Output Format
Output to Standard Output in the following format.
result_char(A string of length 1, representing the extracted character.)
Sample
Hello" tru
"H"
Hello" fals
"o"
oh" tru
"o"
Sample Explanation
Sample 1: The input string is "Hello\