fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. // source number as string
  7. string x;
  8. cin >> x;
  9. // convert it into a number
  10. int y = 0;
  11. for (int i = 0, ilen = x.size(); i < ilen; ++i) {
  12. y *= 8; // it's octal
  13. y += x[i] - '0';
  14. }
  15. // add 1 to that number
  16. ++y;
  17. // if we have a code 7777, next should be 0000
  18. y = y & 07777;
  19. // clear string x, so that we can
  20. x.clear();
  21. // write an octal number there as string
  22. while (y) {
  23. x = char(y % 8 + '0') + x;
  24. y /= 8;
  25. }
  26. // output that number
  27. cout << x << endl;
  28. }
Success #stdin #stdout 0s 3432KB
stdin
1157
stdout
1160