#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(sizeof(char) * (len
* 2 + 1));
/*if (tmp == NULL) { // メモリ確保が失敗した場合
printf("Memory allocation failed.\n");
return NULL;
}*/
// 元の文字列をtmpにコピー
for (int i = 0; i < len; i++) {
tmp[i] = s[i];
}
// 反転した文字列をtmpの後ろに追加
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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpPTA7IHNbaV0hPSdcMCc7IGkrKyk7CiAgICByZXR1cm4gaTsKfQoKLy8g5Zue5paH44KS55Sf5oiQ44GZ44KL6Zai5pWwCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pewogICAgaW50IGxlbiA9IG15U3RybGVuKHMpOwogICAgLy8g5Zue5paH44KS5qC857SN44GZ44KL44Gf44KB44Gu44Oh44Oi44Oq44KS56K65L+dCiAgICBjaGFyICp0bXAgPSAoY2hhciopbWFsbG9jKHNpemVvZihjaGFyKSAqIChsZW4gKiAyICsgMSkpOwoKICAgIC8qaWYgKHRtcCA9PSBOVUxMKSB7ICAvLyDjg6Hjg6Ljg6rnorrkv53jgYzlpLHmlZfjgZfjgZ/loLTlkIgKICAgICAgICBwcmludGYoIk1lbW9yeSBhbGxvY2F0aW9uIGZhaWxlZC5cbiIpOwogICAgICAgIHJldHVybiBOVUxMOwogICAgfSovCgogICAgLy8g5YWD44Gu5paH5a2X5YiX44KSdG1w44Gr44Kz44OU44O8CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgdG1wW2ldID0gc1tpXTsKICAgIH0KCiAgICAvLyDlj43ou6LjgZfjgZ/mloflrZfliJfjgpJ0bXDjga7lvozjgo3jgavov73liqAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbbGVuICsgaV0gPSBzW2xlbiAtIDEgLSBpXTsKICAgIH0KCiAgICB0bXBbbGVuICogMl0gPSAnXDAnOyAvLyDmloflrZfliJfjga7ntYLnq6/jgpLov73liqAKCiAgICByZXR1cm4gdG1wOwp9CgppbnQgbWFpbigpewogICAgaW50IGk7CiAgICBjaGFyIG55dXJ5b2t1WzEwMjRdOyAvLyDlhaXlipvnlKjmloflrZfliJcKICAgIGNoYXIgKmthaWJ1bjsgICAvLyDlm57mlofjgpLlj5fjgZHlj5bjgovjg53jgqTjg7Pjgr8KICAgIHNjYW5mKCIlcyIsIG55dXJ5b2t1KTsKICAgIGthaWJ1biA9IHNldFBhbGluZHJvbWUobnl1cnlva3UpOwogICAgcHJpbnRmKCIlc1xuICAtPiAlc1xuIiwgbnl1cnlva3UsIGthaWJ1bik7CiAgICBmcmVlKGthaWJ1bik7IC8vIOODoeODouODquOBruino+aUvgogICAgcmV0dXJuIDA7Cn0K