fork download
  1. class Solution {
  2. public:
  3. int furthestDistanceFromOrigin(string moves)
  4. {
  5. unordered_map<char, int>m;
  6. int n=moves.size();
  7. int Lvalue=0;
  8. int Rvalue=0;
  9. int DashValue=0;
  10. for(int i=0;i<n;i++)
  11. {
  12. m[moves[i]]++;
  13. }
  14.  
  15. for(auto i: m)
  16. {
  17. if(i.first=='R')
  18. {
  19. Rvalue=i.second;
  20. }
  21. else if(i.first=='L')
  22. {
  23. Lvalue=i.second;
  24. }
  25. else
  26. {
  27. DashValue=i.second;
  28. }
  29. }
  30.  
  31. int result=0;
  32.  
  33. if(Rvalue==0 && Lvalue==0)
  34. {
  35. return DashValue;
  36. }
  37.  
  38. if(Rvalue>Lvalue)
  39. {
  40. result= (Rvalue+ DashValue) - Lvalue;
  41. }
  42. else
  43. {
  44. result=(Lvalue+ DashValue)-Rvalue;
  45. }
  46. return result;
  47. }
  48. };
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:36: error: ‘string’ has not been declared
     int furthestDistanceFromOrigin(string moves)
                                    ^~~~~~
prog.cpp: In member function ‘int Solution::furthestDistanceFromOrigin(int)’:
prog.cpp:5:8: error: ‘unordered_map’ was not declared in this scope
        unordered_map<char, int>m;
        ^~~~~~~~~~~~~
prog.cpp:5:22: error: expected primary-expression before ‘char’
        unordered_map<char, int>m;
                      ^~~~
prog.cpp:6:21: error: request for member ‘size’ in ‘moves’, which is of non-class type ‘int’
         int n=moves.size();
                     ^~~~
prog.cpp:12:13: error: ‘m’ was not declared in this scope
             m[moves[i]]++;
             ^
prog.cpp:12:22: error: invalid types ‘int[int]’ for array subscript
             m[moves[i]]++;
                      ^
prog.cpp:15:21: error: ‘m’ was not declared in this scope
         for(auto i: m)
                     ^
stdout
Standard output is empty