#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, j;
char *tmp;
// メモリ確保: オリジナル文字列 + 逆順文字列 + null 終端
tmp
= (char*)malloc(sizeof(char) * (2 * len
+ 1));
// オリジナル文字列をtmpにコピー
for (i = 0; i < len; i++) {
tmp[i] = s[i];
}
// 逆順文字列をtmpにコピー
for (j = 0; j < len; j++) {
tmp[len + j] = s[len - j - 1]; // 正しく逆順にコピー
}
// null 終端を追加
tmp[2 * len] = '\0';
return tmp;
}
// メイン関数は変更不要
int main() {
char nyuryoku[1024]; // 入力用の配列
char *kaibun; // 回文を受け取るポインタ
scanf("%s", nyuryoku
); // 文字列の入力 kaibun = setPalindrome(nyuryoku); // 回文を生成
printf("%s\n -> %s\n", nyuryoku
, kaibun
); // 結果を表示
free(kaibun
); // 確保したメモリを解放 return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSkgewogICAgaW50IGk7CiAgICBmb3IgKGkgPSAwOyBzW2ldICE9ICdcMCc7IGkrKyk7CiAgICByZXR1cm4gaTsKfQoKLy8g5Zue5paH44KS5L2c5oiQ44GZ44KL6Zai5pWwCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pIHsKICAgIGludCBsZW4gPSBteVN0cmxlbihzKTsKICAgIGludCBpLCBqOwogICAgY2hhciAqdG1wOwogICAgCiAgICAvLyDjg6Hjg6Ljg6rnorrkv506IOOCquODquOCuOODiuODq+aWh+Wtl+WIlyArIOmAhumghuaWh+Wtl+WIlyArIG51bGwg57WC56uvCiAgICB0bXAgPSAoY2hhciopbWFsbG9jKHNpemVvZihjaGFyKSAqICgyICogbGVuICsgMSkpOwogICAgCiAgICAvLyDjgqrjg6rjgrjjg4rjg6vmloflrZfliJfjgpJ0bXDjgavjgrPjg5Tjg7wKICAgIGZvciAoaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgIHRtcFtpXSA9IHNbaV07CiAgICB9CiAgICAKICAgIC8vIOmAhumghuaWh+Wtl+WIl+OCknRtcOOBq+OCs+ODlOODvAogICAgZm9yIChqID0gMDsgaiA8IGxlbjsgaisrKSB7CiAgICAgICAgdG1wW2xlbiArIGpdID0gc1tsZW4gLSBqIC0gMV07ICAvLyDmraPjgZfjgY/pgIbpoIbjgavjgrPjg5Tjg7wKICAgIH0KICAgIAogICAgLy8gbnVsbCDntYLnq6/jgpLov73liqAKICAgIHRtcFsyICogbGVuXSA9ICdcMCc7CiAgICAKICAgIHJldHVybiB0bXA7Cn0KCi8vIOODoeOCpOODs+mWouaVsOOBr+WkieabtOS4jeimgQppbnQgbWFpbigpIHsKICAgIGNoYXIgbnl1cnlva3VbMTAyNF07ICAvLyDlhaXlipvnlKjjga7phY3liJcKICAgIGNoYXIgKmthaWJ1bjsgICAgICAgICAvLyDlm57mlofjgpLlj5fjgZHlj5bjgovjg53jgqTjg7Pjgr8KICAgIAogICAgc2NhbmYoIiVzIiwgbnl1cnlva3UpOyAgLy8g5paH5a2X5YiX44Gu5YWl5YqbCiAgICBrYWlidW4gPSBzZXRQYWxpbmRyb21lKG55dXJ5b2t1KTsgIC8vIOWbnuaWh+OCkueUn+aIkAogICAgCiAgICBwcmludGYoIiVzXG4gIC0+ICVzXG4iLCBueXVyeW9rdSwga2FpYnVuKTsgIC8vIOe1kOaenOOCkuihqOekugogICAgCiAgICBmcmVlKGthaWJ1bik7ICAvLyDnorrkv53jgZfjgZ/jg6Hjg6Ljg6rjgpLop6PmlL4KICAgIHJldHVybiAwOwp9Cg==