首页 > 关注 > > > 正文
CF 1791B - Following Directions
发布时间:2023-07-03 08:31:37   来源:哔哩哔哩  

Alperen is standing at the point (0,0). He is given a string s of length n and performs n moves.


(资料图)

The i-th move is as follows:

if si=L, then move one unit left;

if si=R, then move one unit right;

if si=U, then move one unit up;

if si=D, then move one unit down.

There is a candy at (1,1)(1,1) (that is, one unit above and one unit to the right of Alperen's starting point). You need to determine if Alperen ever passes the candy.

Input

The first line of the input contains an integer t (1≤t≤1000) — the number of testcases.

The first line of each test case contains an integer n (1≤n≤50) — the length of the string.

The second line of each test case contains a string s of length n consisting of characters L, R, D, and U, denoting the moves Alperen makes.

Output

For each test case, output "YES" (without quotes) if Alperen passes the candy, and "NO" (without quotes) otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

easy 题目 模拟,向右则x++,向上则y++,每次判断x,y是否都等于1即可。

等于了,就输出yes,不等于就输出no。

下面是代码:

关键词:

推荐内容

Copyright@  2015-2022 起点器材装备网版权所有  备案号: 皖ICP备2022009963号-12   联系邮箱:295 911 578@qq.com