#include <stdio.h>
#include <stdlib.h>
int myStrlen(char s[]){
int i;
for(i=0;s[i]!='\0';i++);
return i;
}
// 関数の中でtmpに対してmallocして
// そこに回文を代入してreturnで返しましょう
char *setPalindrome(char s[]){
char *tmp;
int len = myStrlen(s);
tmp
= (char *)malloc(sizeof(char) * (len
* 2 + 1));
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[len * 2] = '\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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAppbnQgbXlTdHJsZW4oY2hhciBzW10pewogICAgaW50IGk7CiAgICBmb3IoaT0wO3NbaV0hPSdcMCc7aSsrKTsKICAgIHJldHVybiBpOwp9CiAKLy8g6Zai5pWw44Gu5Lit44GndG1w44Gr5a++44GX44GmbWFsbG9j44GX44GmCi8vIOOBneOBk+OBq+WbnuaWh+OCkuS7o+WFpeOBl+OBpnJldHVybuOBp+i/lOOBl+OBvuOBl+OCh+OBhgpjaGFyICpzZXRQYWxpbmRyb21lKGNoYXIgc1tdKXsKCWNoYXIgKnRtcDsKCWludCBsZW4gPSBteVN0cmxlbihzKTsKIAogICAgdG1wID0gKGNoYXIgKiltYWxsb2Moc2l6ZW9mKGNoYXIpICogKGxlbiAqIDIgKyAxKSk7CiAKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBsZW47IGkrKyl7CiAgICAgICAgdG1wW2ldID0gc1tpXTsKICAgIH0KIAogICAgZm9yKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKXsKICAgICAgICB0bXBbbGVuICsgaV0gPSBzW2xlbiAtIDEgLSBpXTsKICAgIH0KIAogICAgdG1wW2xlbiAqIDJdID0gJ1wwJzsKIAogICAgcmV0dXJuIHRtcDsKfQogCmludCBtYWluKCl7CiAgICBpbnQgaTsKICAgIGNoYXIgbnl1cnlva3VbMTAyNF07CiAgICBjaGFyICprYWlidW47CiAgICBzY2FuZigiJXMiLG55dXJ5b2t1KTsKICAgIGthaWJ1biA9IHNldFBhbGluZHJvbWUobnl1cnlva3UpOwogICAgcHJpbnRmKCIlc1xuICAtPiAlc1xuIixueXVyeW9rdSxrYWlidW4pOwogICAgZnJlZShrYWlidW4pOwogICAgcmV0dXJuIDA7Cn0=