#315. 星号相邻字符判断

    ID: 315 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatString-2gesp3字符串循环结构

星号相邻字符判断

Star Adjacent Character Check

Background

Dawei is designing a string processing program and needs a function to check for a specific character pattern within a string.

Problem Description

Given a string, return true if for every '*' (star) character in the string, the following condition holds: if there are characters both immediately before and immediately after the star, then these two characters must be the same. Otherwise, return false.

Input Format

Input is given from Standard Input in the following format.

A string SS.

Output Format

Output is printed to Standard Output in the following format.

Output true if the condition is met; otherwise, output false.

Sample

xy*yzz
true
xy*zzz
false
*xa*az
true

Sample Explanation

Sample 1: The string is "xy*yzz". The only star is at index 2. The character before it is 'y', and the character after it is 'y'. They are the same, so true is returned.

Sample 2: The string is "xy*zzz". The only star is at index 2. The character before it is 'y', and the character after it is 'z'. They are different, so false is returned.

Sample 3: The string is "xaaz". The first star is at index 0. There is no character before it, so no check is performed. The second star is at index 3. The character before it is 'a', and the character after it is 'a'. They are the same. All stars satisfy the condition, so true is returned.

Constraints

The length of string SS is between 11 and 10001000. String SS contains only lowercase English letters and the '*' character.