#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *setPalindrome(const char *s) {
char *result
= (char *)malloc(2 * len
+ 1); // 回文用のメモリ確保 if (!result) return NULL;
// 元の文字列をコピー
// 逆順に文字を追加
for (int i = 0; i < len; i++) {
result[len + i] = s[len - i - 1];
}
result[2 * len] = '\0'; // 終端文字を追加
return result;
}
int main() {
char input[100];
char *palindrome = setPalindrome(input);
if (palindrome) {
free(palindrome
); // メモリの解放 }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKY2hhciAqc2V0UGFsaW5kcm9tZShjb25zdCBjaGFyICpzKSB7CiAgICBpbnQgbGVuID0gc3RybGVuKHMpOwogICAgY2hhciAqcmVzdWx0ID0gKGNoYXIgKiltYWxsb2MoMiAqIGxlbiArIDEpOyAvLyDlm57mlofnlKjjga7jg6Hjg6Ljg6rnorrkv50KICAgIGlmICghcmVzdWx0KSByZXR1cm4gTlVMTDsKCiAgICAvLyDlhYPjga7mloflrZfliJfjgpLjgrPjg5Tjg7wKICAgIHN0cmNweShyZXN1bHQsIHMpOwoKICAgIC8vIOmAhumghuOBq+aWh+Wtl+OCkui/veWKoAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgIHJlc3VsdFtsZW4gKyBpXSA9IHNbbGVuIC0gaSAtIDFdOwogICAgfQogICAgcmVzdWx0WzIgKiBsZW5dID0gJ1wwJzsgLy8g57WC56uv5paH5a2X44KS6L+95YqgCgogICAgcmV0dXJuIHJlc3VsdDsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIGlucHV0WzEwMF07CiAgICBzY2FuZigiJXMiLCBpbnB1dCk7CgogICAgY2hhciAqcGFsaW5kcm9tZSA9IHNldFBhbGluZHJvbWUoaW5wdXQpOwogICAgaWYgKHBhbGluZHJvbWUpIHsKICAgICAgICBwcmludGYoIiVzXG4iLCBwYWxpbmRyb21lKTsKICAgICAgICBmcmVlKHBhbGluZHJvbWUpOyAvLyDjg6Hjg6Ljg6rjga7op6PmlL4KICAgIH0KCiAgICByZXR1cm4gMDsKfQoK