A. Is It a Cat?

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line of input data contains a single integer t� (1≤t≤1041≤�≤104) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains an integer n� (1≤n≤501≤�≤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.

Output

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).

Example

input

Copy

 

7

4

meOw

14

mMmeoOoWWWwwwW

3

mew

7

MmeEeUw

4

MEOW

6

MmyaVW

5

meowA

output

Copy

YES
YES
NO
NO
YES
NO
NO

Note

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 33 characters 'm' and 'M', one 'e', a sequence of 33 characters 'o' and 'O' and a sequence of 77 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.

5

解题说明:此题是一道字符串题,可以先将所有字母转换为小写字母,然后在遍历判断是不是出现meow,最后比较即可。

#include<string.h>
int main()
{
	int m;
	scanf("%d", &m);
	while (m--)
	{
		int n, x = 0, i;
		scanf("%d", &n);
		char p[1000], q[1000], r[1000] = "meow";
		scanf("%s", &p);
		strlwr(p);
		for (i = 0; i < n; i++)
		{
			if (p[i + 1] != p[i])
			{
				q[x++] = p[i];
			}
		}
		q[x++] = '\0';
		if (strcmp(q, r) == 0)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值