Advertisement
Promi_38

cf 712B

Jan 23rd, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.     char s[100005];
  8.     scanf("%s", s);
  9.    
  10.     if(strlen(s) % 2 != 0) printf("-1\n");
  11.     else
  12.     {
  13.         int x = 0, y = 0;
  14.         for(int i = 0; i < strlen(s); i++)
  15.         {
  16.             if(s[i] == 'L') x--;
  17.             if(s[i] == 'R') x++;
  18.             if(s[i] == 'U') y++;
  19.             if(s[i] == 'D') y--;
  20.         }
  21.         printf("%d\n", (abs(x) + abs(y)) / 2);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement