Artifact 97604476ec6f936736b2a887e9d2a4763ec156d1
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class NextPalindromicNumber { public:
string getNext(string n)
{
string s = mirror(n);
if( n < s )
return s;
return mirror(plus1(s, (s.size()-1)/2));
}
string mirror(const string& s)
{
return string(s.begin(), s.begin()+s.size()/2) + string(s.rbegin()+s.size()/2, s.rend());
}
string plus1(string s, int i)
{
while( s[i] == '9' )
{
s[i--] = '0';
if( i < 0 )
return '1'+s;
}
s[i]++;
return s;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, NextPalindromicNumber().getNext(n));}
int main(){
CASE(0)
string n = "12345";
string _ = "12421";
END
CASE(1)
string n = "858";
string _ = "868";
END
CASE(2)
string n = "1999";
string _ = "2002";
END
CASE(3)
string n = "1";
string _ = "2";
END
CASE(4)
string n = "9999";
string _ = "10001";
END
/*
CASE(5)
string n = ;
string _ = ;
END
CASE(6)
string n = ;
string _ = ;
END
*/
}
// END CUT HERE