#315. 星号相邻字符判断
星号相邻字符判断
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 .
Output Format
Output is printed to Standard Output in the following format.
Output
trueif the condition is met; otherwise, outputfalse.
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 is between and .
String contains only lowercase English letters and the '*' character.