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