#include #include #include using namespace std; string numtostring(int myint) { string numstring; stringstream ss; ss << myint; ss >> numstring; return (numstring); } int stringtonum(string mystring) { unsigned int stringnum; istringstream (mystring) >> stringnum; return (stringnum); } string reversedigits(string numbertoreverse) { string numreversed; long i = (unsigned) numbertoreverse.size() - 1; while(i >= 0){ string u; stringstream ss; ss << numbertoreverse[i]; ss >> u; numreversed.append(u); i--; } return (numreversed); } int main() { unsigned int intervalstart = 2; unsigned int intervalend = 10000; unsigned int testcandidate; string seq = ""; while(intervalstart <= intervalend){ unsigned int origseed = 1; testcandidate = intervalstart; while(origseed < intervalstart){ unsigned int seed = origseed; while(seed < testcandidate){ string seedstr = numtostring(seed); string seedstrrev = reversedigits(seedstr); seed = stringtonum(seedstr); unsigned int seedrev = stringtonum(seedstrrev); seed = seed + seedrev; if(seed == testcandidate){ string seqterm1 = numtostring(intervalstart); string seqterm2 = numtostring(origseed); seq += seqterm1; seq += ", "; seq += seqterm2; seq += ", "; origseed = intervalstart; } } origseed++; } intervalstart++; } cout << seq << endl; return 0; }