Jenifa

Leetcode 657: Robot return to Origin

May 29th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3.  
  4.  
  5. class solution{
  6.  
  7. public:
  8.  
  9.    bool judgeCircle( std::string moves )
  10.    {
  11.        if( std::count( moves.begin(), moves.end(), 'L') != std::count( moves.begin(), moves.end(), 'R'))
  12.        {
  13.            return false;
  14.  
  15.        }else if( std::count( moves.begin(), moves.end(), 'D') != std::count( moves.begin(), moves.end(), 'U')) {
  16.  
  17.            return false;
  18.  
  19.        }
  20.  
  21.        return true;
  22.    }
  23.  
  24.  
  25. };
  26.  
  27. int main()
  28. {
  29.     solution sol;
  30.  
  31.     bool result;
  32.  
  33.     std::string input;
  34.  
  35.     std::cin>>input;
  36.  
  37.     std::transform( input.begin(), input.end(), input.begin(), [](unsigned char c) { return std::toupper(c); } );
  38.  
  39.     result = sol.judgeCircle(input);
  40.  
  41.     if(result == 0)
  42.     {
  43.         std::cout<<"false"<<std::endl;
  44.  
  45.     }else {
  46.  
  47.         std::cout<<"true"<<std::endl;
  48.  
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment