fork download
  1. class Solution {
  2. public:
  3. int mirrorDistance(int n) {
  4. // Convert number to string
  5. string str = to_string(n);
  6.  
  7. // Reverse the string
  8. reverse(str.begin(), str.end());
  9.  
  10. // Convert reversed string back to number
  11. long long rev = stoll(str);
  12.  
  13. // Return absolute difference
  14. return abs(n - rev);
  15. }
  16. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘int Solution::mirrorDistance(int)’:
prog.cpp:5:9: error: ‘string’ was not declared in this scope
         string str = to_string(n);
         ^~~~~~
prog.cpp:5:9: note: suggested alternative: ‘struct’
         string str = to_string(n);
         ^~~~~~
         struct
prog.cpp:8:17: error: ‘str’ was not declared in this scope
         reverse(str.begin(), str.end());
                 ^~~
prog.cpp:8:17: note: suggested alternative: ‘std’
         reverse(str.begin(), str.end());
                 ^~~
                 std
prog.cpp:8:9: error: ‘reverse’ was not declared in this scope
         reverse(str.begin(), str.end());
         ^~~~~~~
prog.cpp:11:25: error: ‘stoll’ was not declared in this scope
         long long rev = stoll(str);
                         ^~~~~
prog.cpp:14:16: error: ‘abs’ was not declared in this scope
         return abs(n - rev);
                ^~~
stdout
Standard output is empty