#include <stdio.h>
#include <stdlib.h>
int myStrlen(char s[]){
int i;
for(i = 0; s[i] != '\0'; i++);
return i;
}
char *setPalindrome(char s[]){
int len = myStrlen(s);
char *tmp
= (char *)malloc((2 * len
+ 1) * sizeof(char)); if (tmp == NULL) return NULL;
for (int i = 0; i < len; i++) {
tmp[i] = s[i];
}
for (int i = 0; i < len; i++) {
tmp[len + i] = s[len - i - 1];
}
tmp[2 * len] = '\0';
return tmp;
}
int main(){
int i;
char nyuryoku[1024];
char *kaibun;
kaibun = setPalindrome(nyuryoku);
if (kaibun != NULL) {
printf("%s\n -> %s\n", nyuryoku
, kaibun
); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpID0gMDsgc1tpXSAhPSAnXDAnOyBpKyspOwogICAgcmV0dXJuIGk7Cn0KCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pewogICAgaW50IGxlbiA9IG15U3RybGVuKHMpOwogICAgY2hhciAqdG1wID0gKGNoYXIgKiltYWxsb2MoKDIgKiBsZW4gKyAxKSAqIHNpemVvZihjaGFyKSk7CiAgICBpZiAodG1wID09IE5VTEwpIHJldHVybiBOVUxMOwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbaV0gPSBzW2ldOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgIHRtcFtsZW4gKyBpXSA9IHNbbGVuIC0gaSAtIDFdOwogICAgfQogICAgdG1wWzIgKiBsZW5dID0gJ1wwJzsKCiAgICByZXR1cm4gdG1wOwp9CgppbnQgbWFpbigpewogICAgaW50IGk7CiAgICBjaGFyIG55dXJ5b2t1WzEwMjRdOwogICAgY2hhciAqa2FpYnVuOwogICAgc2NhbmYoIiVzIiwgbnl1cnlva3UpOwogICAga2FpYnVuID0gc2V0UGFsaW5kcm9tZShueXVyeW9rdSk7CiAgICBpZiAoa2FpYnVuICE9IE5VTEwpIHsKICAgICAgICBwcmludGYoIiVzXG4gIC0+ICVzXG4iLCBueXVyeW9rdSwga2FpYnVuKTsKICAgICAgICBmcmVlKGthaWJ1bik7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==