Skip to content

Commit b78974e

Browse files
committed
Added 1791B - Following Directions.cpp
1 parent 6c4d26c commit b78974e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

1791B - Following Directions.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
#define ll long long
5+
6+
// Code Written By: Vikash Patel
7+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
8+
9+
bool check(string s, int n)
10+
{
11+
int x=0,y=0;
12+
for(int i=0;i<n;i++)
13+
{
14+
if(s[i]=='U')
15+
y++;
16+
if(s[i]=='D')
17+
y--;
18+
if(s[i]=='R')
19+
x++;
20+
if(s[i]=='L')
21+
x--;
22+
if(x==1 && y==1)
23+
return 1;
24+
}
25+
return 0;
26+
}
27+
int main()
28+
{
29+
int t;
30+
cin>>t;
31+
while(t--)
32+
{
33+
int n;
34+
cin>>n;
35+
string s;
36+
cin>>s;
37+
cout<<((check(s,n))?"YES":"NO")<<endl;
38+
}
39+
return 0;
40+
}

0 commit comments

Comments
 (0)