fork download
  1. #include <utility> // for std::swap
  2. #include <set>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <string>
  6. #include <iostream>
  7. using namespace std;
  8. int x; string input;
  9.  
  10. int findPalindrome(int min) {
  11. x = min + 1;
  12. while (x>min) {
  13.  
  14. std::string input = std::to_string(x);
  15. if (input == string(input.rbegin(), input.rend())) {
  16. break;
  17. }
  18. ++x;
  19. }
  20. return x;
  21. }
  22.  
  23. int main() {
  24.  
  25. int num, focus[50], lx = 1; string ret = "";
  26. cin >> num;
  27. while (lx <= num) {
  28. cin>>focus[lx];
  29. lx=lx+1;
  30. }
  31. lx=1;
  32. while (lx <= num) {
  33. ret += std::to_string(findPalindrome(focus[lx]));
  34. ret += "\n";
  35. lx=lx+1;
  36. }
  37. cout << ret;
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3476KB
stdin
9
21
2133
2000
23456
50000
803417
987654321
9876543210
98765432101


stdout
22
2222
2002
23532
50005
804408
987656789
-2147483647
2