-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVNCA.cpp
More file actions
56 lines (50 loc) · 974 Bytes
/
VNCA.cpp
File metadata and controls
56 lines (50 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<stdio.h>
using namespace std;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int check(string s){
int X = 0,Y = 0;
int x = 0,y = 0;
int len = s.size();
for(int i=0;i<len;i++){
if(s[i]=='R'){
x = x + dx[0];
y = y + dy[0];
}
else if(s[i]=='L'){
x = x + dx[1];
y = y + dy[1];
}
else if(s[i]=='U'){
x = x + dx[2];
y = y + dy[2];
}
else if(s[i]=='D'){
x = x + dx[3];
y = y + dy[3];
}
}
if(x==0&&y==0) {
return 1;
}
return 0;
}
int main(){
string s,t;
int n,cnt=0;
while(cin>>n){
cin>>s;
cnt = 0;
for(int i=0;i<n;i++){
for(int j=1;j<=n-i;j++){
t = s.substr(i,j);
if(check(t)==1) {
//cout<<t<<endl;
cnt++;
}
}
}
cout<<cnt<<endl;
}
}