A15849 | Is It a Cat?
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You were walking down the street and heard a sound. The sound was described by the string $s$ consisting of lowercase and uppercase Latin characters. Now you want to find out if the sound was a cat meowing.
For the sound to be a meowing, the string can only contain the letters 'm', 'e', 'o' and 'w', in either uppercase or lowercase. Also:
- string must start with non-empty sequence consisting only of characters 'm' or 'M'
- it must be immediately followed by non-empty sequence consisting only of characters 'e' or 'E'
- it must be immediately followed by non-empty sequence consisting only of characters 'o' or 'O'
- it must be immediately followed by non-empty sequence consisting only of characters 'w' or 'W', this sequence ends the string, after it immediately comes the string end
For example, strings "meow", "mmmEeOWww", "MeOooOw" describe a meowing, but strings "Mweo", "MeO", "moew", "MmEW", "meowmeow" do not.
Determine whether the sound you heard was a cat meowing or something else.
For the sound to be a meowing, the string can only contain the letters 'm', 'e', 'o' and 'w', in either uppercase or lowercase. Also:
- string must start with non-empty sequence consisting only of characters 'm' or 'M'
- it must be immediately followed by non-empty sequence consisting only of characters 'e' or 'E'
- it must be immediately followed by non-empty sequence consisting only of characters 'o' or 'O'
- it must be immediately followed by non-empty sequence consisting only of characters 'w' or 'W', this sequence ends the string, after it immediately comes the string end
For example, strings "meow", "mmmEeOWww", "MeOooOw" describe a meowing, but strings "Mweo", "MeO", "moew", "MmEW", "meowmeow" do not.
Determine whether the sound you heard was a cat meowing or something else.
输入格式
The first line of input data contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
The description of the test cases follows.
The first line of each test case contains an integer $n$ ( $1 \le n \le 50$ ) — the length of the string describing the sound.
The second line of each test case contains a string $s$ of $n$ characters. The string describes the sound you heard and consists only of lowercase and uppercase Latin letters.
The description of the test cases follows.
The first line of each test case contains an integer $n$ ( $1 \le n \le 50$ ) — the length of the string describing the sound.
The second line of each test case contains a string $s$ of $n$ characters. The string describes the sound you heard and consists only of lowercase and uppercase Latin letters.
输出格式
For each test case, output on a separate line:
- YES if the sound was a cat meowing;
- NO otherwise.
You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).
- YES if the sound was a cat meowing;
- NO otherwise.
You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).
输入输出样例
输入 #1
7 4 meOw 14 mMmeoOoWWWwwwW 3 mew 7 MmeEeUw 4 MEOW 6 MmyaVW 5 meowA
输出 #1
YES YES NO NO YES NO NO
In the first test case, the string consists of a sequence of characters 'm', 'e', 'O', 'w', which satisfies the definition of meowing.
In the second test case, the string consists of a sequence of $3$ characters 'm' and 'M', one 'e', a sequence of $3$ characters 'o' and 'O' and a sequence of $7$ characters 'w' and 'W', which satisfies the definition of meowing.
In the third test case, the string does not describe a meowing because it lacks a sequence of 'o' or 'O' characters between 'e' and 'w'.
In the fourth test case, the string contains the character 'U', so it does not describe a meowing.
In the second test case, the string consists of a sequence of $3$ characters 'm' and 'M', one 'e', a sequence of $3$ characters 'o' and 'O' and a sequence of $7$ characters 'w' and 'W', which satisfies the definition of meowing.
In the third test case, the string does not describe a meowing because it lacks a sequence of 'o' or 'O' characters between 'e' and 'w'.
In the fourth test case, the string contains the character 'U', so it does not describe a meowing.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted