#59. 判断字符串中所有'g'是否快乐
判断字符串中所有'g'是否快乐
Happy 'g'
Background
Congcong is currently learning string processing and has encountered an interesting problem.
Problem Description
We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return true if all the 'g's in the given string are happy.
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 all 'g's are happy, otherwise outputfalse.
Sample
xxggxx
true
xxgxx
false
xxggyygxx
false
Sample Explanation
Sample 1: The string is "xxggxx". The first 'g' has a 'g' to its right, and the second 'g' has a 'g' to its left. All 'g's are happy, so output true.
Sample 2: The string is "xxgxx". The only 'g' has no 'g' to its left or right. It is not happy, so output false.
Sample 3: The string is "xxggyygxx". The first two 'g's are happy. However, the last 'g' has no 'g' to its left or right. It is not happy, so output false.
Constraints
The length of string is between and . The string contains only lowercase English letters.