#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);
int new_len = len * 2;
char *tmp
= (char *)malloc((new_len
+ 1) * sizeof(char));
if (tmp == NULL) {
printf("Memory allocation failed\n"); }
for (int i = 0; i < len; i++) {
tmp[i] = s[i];
}
for (int i = 0; i < len; i++) {
tmp[len + i] = s[len - 1 - i];
}
tmp[new_len] = '\0';
return tmp;
}
int main() {
char nyuryoku[1024];
char *kaibun;
kaibun = setPalindrome(nyuryoku);
printf("%s\n -> %s\n", nyuryoku
, kaibun
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSkgewogICAgaW50IGk7CiAgICBmb3IgKGkgPSAwOyBzW2ldICE9ICdcMCc7IGkrKyk7CiAgICByZXR1cm4gaTsKfQoKY2hhciAqc2V0UGFsaW5kcm9tZShjaGFyIHNbXSkgewogICAgaW50IGxlbiA9IG15U3RybGVuKHMpOyAKICAgIGludCBuZXdfbGVuID0gbGVuICogMjsKICAgIGNoYXIgKnRtcCA9IChjaGFyICopbWFsbG9jKChuZXdfbGVuICsgMSkgKiBzaXplb2YoY2hhcikpOwoKICAgIGlmICh0bXAgPT0gTlVMTCkgewogICAgICAgIHByaW50ZigiTWVtb3J5IGFsbG9jYXRpb24gZmFpbGVkXG4iKTsKICAgICAgICBleGl0KDEpOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbaV0gPSBzW2ldOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbbGVuICsgaV0gPSBzW2xlbiAtIDEgLSBpXTsKICAgIH0KCiAgICB0bXBbbmV3X2xlbl0gPSAnXDAnOwogICAgcmV0dXJuIHRtcDsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIG55dXJ5b2t1WzEwMjRdOwogICAgY2hhciAqa2FpYnVuOwogICAgc2NhbmYoIiVzIiwgbnl1cnlva3UpOwogICAga2FpYnVuID0gc2V0UGFsaW5kcm9tZShueXVyeW9rdSk7CiAgICBwcmludGYoIiVzXG4gIC0+ICVzXG4iLCBueXVyeW9rdSwga2FpYnVuKTsKICAgIGZyZWUoa2FpYnVuKTsKICAgIHJldHVybiAwOwp9Cg==