fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int t;
  7. cin>>t;
  8. while(t--){
  9. string s;
  10. cin>>s;
  11. int x=0;
  12. int y=0;
  13. for(int i=0; i<s.size(); i++){
  14. if(s[i]=='U'){
  15. y++;
  16. }
  17. else if(s[i]=='D') y--;
  18. else if(s[i]=='L')x--;
  19. else if(s[i]=='R') x++;
  20. }
  21. cout<<x<<","<<y<<endl;
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5292KB
stdin
4
UUUDDLRRLD
LLRRL
DDDUU
LRLRLRL
stdout
0,0
-1,0
0,-1
-1,0