Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- int main()
- {
- char s[100005];
- scanf("%s", s);
- if(strlen(s) % 2 != 0) printf("-1\n");
- else
- {
- int x = 0, y = 0;
- for(int i = 0; i < strlen(s); i++)
- {
- if(s[i] == 'L') x--;
- if(s[i] == 'R') x++;
- if(s[i] == 'U') y++;
- if(s[i] == 'D') y--;
- }
- printf("%d\n", (abs(x) + abs(y)) / 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement