#abc296a. A - Alternately
A - Alternately
Score : points
问题陈述
有一排共 个人。他们由长度为 的字符串 描述。若第 个字符为 M
,则表示从前往后数的第 个人是男性;若为 F
,则表示该人是女性。
确定这一排男性和女性是否交替站立。
我们称男性和女性是交替站立的,当且仅当不存在任何位置使得相邻的两个人都是男性或都是女性。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a row of people. They are described by a string of length . The -th person from the front is male if the -th character of is M
, and female if it is F
.
Determine whether the men and women are alternating.
It is said that the men and women are alternating if and only if there is no position where two men or two women are adjacent.
Constraints
- is an integer.
- is a string of length consisting of
M
andF
.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if the men and women are alternating, and No
otherwise.
Sample Input 1
6
MFMFMF
Sample Output 1
Yes
There is no position where two men or two women are adjacent, so the men and women are alternating.
Sample Input 2
9
FMFMMFMFM
Sample Output 2
No
Sample Input 3
1
F
Sample Output 3
Yes
update @ 2024/3/10 12:17:33