#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 total_len = 2 * len;
char *tmp
= (char *)malloc((total_len
+ 1) * sizeof(char)); // 終端文字分のメモリを確保
if (tmp == NULL) {
fprintf(stderr
, "Memory allocation failed\n"); return NULL;
}
// 文字列を結合して回文を作成する
for (int i = 0; i < len; i++) {
tmp[i] = s[i]; // 元の文字列をコピー
tmp[total_len - 1 - i] = s[i]; // 逆順にコピー
}
tmp[total_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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpID0gMDsgc1tpXSAhPSAnXDAnOyBpKyspOwogICAgcmV0dXJuIGk7Cn0KCi8vIOWbnuaWh+OCkuS9nOaIkOOBmeOCi+mWouaVsApjaGFyICpzZXRQYWxpbmRyb21lKGNoYXIgc1tdKSB7CiAgICBpbnQgbGVuID0gbXlTdHJsZW4ocyk7CiAgICBpbnQgdG90YWxfbGVuID0gMiAqIGxlbjsKICAgIGNoYXIgKnRtcCA9IChjaGFyICopbWFsbG9jKCh0b3RhbF9sZW4gKyAxKSAqIHNpemVvZihjaGFyKSk7IC8vIOe1guerr+aWh+Wtl+WIhuOBruODoeODouODquOCkueiuuS/nQoKICAgIGlmICh0bXAgPT0gTlVMTCkgewogICAgICAgIGZwcmludGYoc3RkZXJyLCAiTWVtb3J5IGFsbG9jYXRpb24gZmFpbGVkXG4iKTsKICAgICAgICByZXR1cm4gTlVMTDsKICAgIH0KCiAgICAvLyDmloflrZfliJfjgpLntZDlkIjjgZfjgablm57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