Assuming that you input is abc1def2hij3klm
and you are looking for mlk1jih2fed3cba
as output. It can be achieved in two pass -
1st Pass: reverse the whole string which will give you mlk3jih2fed1cba (you can google to find out the code or if you are using c++ or something similar you can use the library function.
2nd pass: Now your task is to identify the digits if it is digits then reverse it back and insert it at the position. Use the following algo to achieve the same
a[]= "abc1def2hij3klm"
b[] = reverse a;
c[]; /* temp array to store the digit */
d[]; /* temp array to store the digit location */
l=0;
for i=0 to i<length of the string b
if IS_DIGIT(b[i])
c[l] = b[i]
d[l] = i;
e[] = reverse c;
for i=0 to i<length of the string e
b[d[i]] = e[i]
return b;