#276. 字符串首尾字符提取

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

字符串首尾字符提取

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 string S and a boolean flag. The format of input_line is S" B, where S is the original string and B is 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\