fork download
  1. class Solution {
  2. public:
  3.  
  4. int digit(int n)
  5. {
  6. int mx=0;
  7. int mn=9;
  8.  
  9. while(n>0)
  10. {
  11. int d = n % 10;
  12. mx = max(mx, d);
  13. mn = min(mn, d);
  14.  
  15. n=n/10;
  16. }
  17. return mx - mn;
  18. }
  19.  
  20. int maxDigitRange(vector<int> b)
  21. {
  22. int best = 0;
  23.  
  24. for(int x: b)
  25. {
  26. best = max(best , digit(x));
  27. }
  28.  
  29. int a = 0;
  30. for(int x: b)
  31. {
  32. if(digit(x) == best)
  33. {
  34. a = a + x;
  35. }
  36. }
  37. return a;
  38. }
  39.  
  40. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:20:23: error: ‘vector’ has not been declared
     int maxDigitRange(vector<int> b)
                       ^~~~~~
prog.cpp:20:29: error: expected ‘,’ or ‘...’ before ‘<’ token
     int maxDigitRange(vector<int> b)
                             ^
prog.cpp: In member function ‘int Solution::digit(int)’:
prog.cpp:12:22: error: ‘max’ was not declared in this scope
                 mx = max(mx, d);
                      ^~~
prog.cpp:12:22: note: suggested alternative: ‘mx’
                 mx = max(mx, d);
                      ^~~
                      mx
prog.cpp:13:22: error: ‘min’ was not declared in this scope
                 mn = min(mn, d);
                      ^~~
prog.cpp:13:22: note: suggested alternative: ‘mn’
                 mn = min(mn, d);
                      ^~~
                      mn
prog.cpp: In member function ‘int Solution::maxDigitRange(int)’:
prog.cpp:24:20: error: ‘b’ was not declared in this scope
         for(int x: b)
                    ^
prog.cpp:26:20: error: ‘max’ was not declared in this scope
             best = max(best , digit(x));
                    ^~~
prog.cpp:30:20: error: ‘b’ was not declared in this scope
         for(int x: b)
                    ^
stdout
Standard output is empty