done
test is 7957 - next palindrome is 7997, but my code gave me 8008 
edit: hm. Tests are working perfectly - every single test i can find in web... Still WA
here is corrected code:
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <stdio.h>
using namespace std;
bool isPalyndrome(string &numStr) {
string reverseStr(numStr.length(), ' ');
std::copy(numStr.begin(), numStr.end(), reverseStr.begin());
std::reverse(reverseStr.begin(), reverseStr.end());
return reverseStr.compare(numStr);
}
void insertNumber(string &numStr, int num, int eraseIdx) {
char chr = num + '0';
numStr.insert(eraseIdx, 1, chr);
numStr.erase(eraseIdx + 1, 1);
}
void mirroredString(string &originalStr) {
int idx = 0;
int backIdx = originalStr.length() - 1;
while (true) {
originalStr[backIdx] = originalStr[idx];
idx++;
backIdx--;
if (idx >= backIdx)
break;
}
}
bool isLeftGreater(string &originalStr) {
bool result = true;
int idx = 0;
int backIdx = originalStr.length() - 1;
while (true) {
char zeroChar = originalStr.at(idx);
char lastChar = originalStr.at(backIdx);
int zeroCharInt = 0;
int lastCharInt = 0;
sscanf(&zeroChar, "%d", &zeroCharInt);
sscanf(&lastChar, "%1d", &lastCharInt);
if (idx != 0) {
if (zeroCharInt > lastCharInt) {
result = true;
} else
if ((zeroCharInt < lastCharInt) && result) {
result = false;
}
} else
if (zeroCharInt < lastCharInt)
result = false;
idx++;
backIdx--;
if (idx >= backIdx)
break;
}
return result;
}
int main() {
int lineCount = 0;
vector<string> palyns;
cin >> lineCount;
for (int i = 0; i < lineCount; i++) {
string numStr;
cin >> numStr;
bool isNew = true;
while (true) {
if (isNew) {
if (!isPalyndrome(numStr)) {
} else {
if (isLeftGreater(numStr)) {
mirroredString(numStr);
if (!isPalyndrome(numStr)) {
palyns.push_back(numStr);
break;
}
}
}
isNew = false;
}
int idx = numStr.length() / 2; // get the middle idx
if (numStr.length() == 1)
idx = 0;
else
if ((numStr.length() % 2) == 0)
idx--;
while (true) {
if (idx < 0) {
numStr.insert(0, 1, '1');
break;
}
char chr = numStr.at(idx);
int val = atoi(&chr);
val++;
if (val == 10) {
insertNumber(numStr, 0, idx < 0 ? 0 : idx);
idx--;
continue;
} else {
insertNumber(numStr, val, idx < 0 ? 0 : idx);
break;
}
}
mirroredString(numStr);
if (!isPalyndrome(numStr)) {
palyns.push_back(numStr);
break;
}
else
continue;
}
}
for (vector<string>::iterator it = palyns.begin(); it < palyns.end(); it++)
cout << *it << "\n";
return 0;
}
please, HELP!!!! It's driving me crazy.
numbers for testing:
10
1
2
3
4
5
6
7
8
9
10
16
3
9
53936
53236
67775
99
999
6339
875111
6997
7957
9798
2107
3109
456156
2133