How to Reduce Running time

I have the following code
#include
#include
#include
#include
#include
#include
using namespace std;
string mapp=“0123456789”;
inline string addone(string a,int loc){
a[loc]=‘0’;
loc–;
for (;loc>=0;loc–){
if (a[loc]==‘9’)a[loc]=‘0’;
else {a[loc]=mapp[mapp.find(a[loc])+1];break;}

}

return a;

}
int main() {
int t;
scanf(“%d”,&t);
getchar();
for (;t>0;t–){
char g[1000001];
gets(g);
string a;
a=g;
a=‘0’+a;
for (int c(a.size()-1);c>=0;c–){
if (a[c]==‘9’)a[c]=‘0’;
else {a[c]=mapp[mapp.find(a[c])+1];break;}
}
if (a[0]==‘0’)a.erase(a.begin());
int c(a.size()-1),c1(0);
for (;c>=0&&c1<floor((a.size()+1)/2);c–,c1++){
if (a[c1]<a[c])a=addone(a,c);
if (a[c1]>a[c])a[c]=a[c1];

}
cout << a << endl;
}
return 0;
}

This is the code for PALIN Problem - CodeChef I would like to know how to reduce the time

Any one (@betlista,@vineetpaliwal,@kuruma or any other) please help me

Use an efficient algo such as DP

How this problem is related to DP can you please elaborate