Here is my code:
#include <iostream>
#include <string>
#include <utility>
int main(){
std::string swapInt, b;
int testCase, integer;
bool loop;
std::cin>>testCase;
while(testCase--){
std::cin>>integer;
int a = integer;
integer++;
loop = true;
if(a >= 1000000 || a<=0){
std::cout<<"Error, number too extreme\n"<<std::endl;
loop = false;
testCase++;
}
while(loop){
std::string temp = std::to_string(integer);
b = temp;
swapInt = b;
for(long long unsigned int i=0;i<b.size()/2;i++){
std::swap(swapInt[i], swapInt[swapInt.size()-i-1]);
}
if(swapInt==b){
loop = false;
break;
}else{
int temp2 = std::stoi(b);
temp2++;
integer = temp2;
}
}
if(a >= 1000000 || a<= 0){
continue;
}else{
std::cout<<"Nearest Palindrome is: "<<b<<std::endl;
}
}
return 0;
}
It has appeared to me that this code met all the criteria, though the runtime error has still occurred
Here is the link to the question: https://www.spoj.com/problems/PALIN/