首页 >行业动态 > > 正文

环球今日报丨CF 1791B - Following Directions

发布日期:2023-07-03 08:29:05 来源:哔哩哔哩 分享

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备2021034106号-51   联系邮箱:5 516 538 @qq.com