#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;
tmp
= (char*)malloc((2 * len
+ 1) * sizeof(char));
if (tmp == NULL) {
printf("Memory allocation failed\n"); 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 - 1 - i];
}
tmp[2 * len] = '\0';
return tmp;
}
int main(){
int i;
char nyuryoku[1024]; //入力
char *kaibun; //回文を受け取る
kaibun = setPalindrome(nyuryoku);
printf("%s\n -> %s\n",nyuryoku
,kaibun
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCgppbnQgbXlTdHJsZW4oY2hhciBzW10pIHsKICAgIGludCBpOwogICAgZm9yIChpID0gMDsgc1tpXSAhPSAnXDAnOyBpKyspOwogICAgcmV0dXJuIGk7Cn0KCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pIHsKICAgIGludCBsZW4gPSBteVN0cmxlbihzKTsgCiAgICBjaGFyICp0bXA7ICAgICAgICAgICAgIAoKICAgIHRtcCA9IChjaGFyKiltYWxsb2MoKDIgKiBsZW4gKyAxKSAqIHNpemVvZihjaGFyKSk7IAoKICAgIGlmICh0bXAgPT0gTlVMTCkgewogICAgICAgIAogICAgICAgIHByaW50ZigiTWVtb3J5IGFsbG9jYXRpb24gZmFpbGVkXG4iKTsKICAgICAgICByZXR1cm4gTlVMTDsKICAgIH0KCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgdG1wW2ldID0gc1tpXTsKICAgIH0KCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgdG1wW2xlbiArIGldID0gc1tsZW4gLSAxIC0gaV07CiAgICB9CgogICAgdG1wWzIgKiBsZW5dID0gJ1wwJzsKCiAgICByZXR1cm4gdG1wOyAKfQoKaW50IG1haW4oKXsKICAgIGludCBpOwogICAgY2hhciBueXVyeW9rdVsxMDI0XTsgLy/lhaXlipsKICAgIGNoYXIgKmthaWJ1bjsgICAvL+WbnuaWh+OCkuWPl+OBkeWPluOCiwogICAgc2NhbmYoIiVzIixueXVyeW9rdSk7CiAgICBrYWlidW4gPSBzZXRQYWxpbmRyb21lKG55dXJ5b2t1KTsKICAgIHByaW50ZigiJXNcbiAgLT4gJXNcbiIsbnl1cnlva3Usa2FpYnVuKTsKICAgIGZyZWUoa2FpYnVuKTsKICAgIHJldHVybiAwOwp9