fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. bool isKaibun(int n) {
  5. std::vector<int> k;
  6. if (n > 0) {
  7. while (n > 0) {
  8. k.push_back(n % 10);
  9. n = n / 10;
  10. }
  11. auto stt = k.begin();
  12. auto end = k.end() - 1;
  13. for (; stt != k.end(); stt++, end--)
  14. if (*stt != *end)
  15. return false;
  16. return true;
  17. } else if (n == 0)
  18. return true;
  19. else
  20. return false;
  21. }
  22.  
  23. void f(int n) {
  24. bool stopflag = true;
  25. std::cout << "input: " << n << std::endl;
  26. for (int x = n, y = n; stopflag; x++, y--) {
  27. if (isKaibun(x)) {
  28. std::cout << "output: " << x << std::endl;
  29. stopflag = false;
  30. }
  31. if (isKaibun(y) && x != y) {
  32. std::cout << "output: " << y << std::endl;
  33. stopflag = false;
  34. }
  35. }
  36. std::cout << std::endl;
  37. }
  38.  
  39. int main() {
  40. f(0);
  41. f(17);
  42. f(100);
  43. f(1000);
  44. }
  45. /* end */
  46.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
input: 0
output: 0

input: 17
output: 22

input: 100
output: 101
output: 99

input: 1000
output: 1001
output: 999