#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 回文を生成する関数
char *setPalindrome(const char *s) {
// 入力文字列の長さを取得
// 新しい文字列の長さを計算(元の文字列+逆順文字列)
int new_len = 2 * len;
// 動的メモリの確保
char *palindrome
= (char *)malloc((new_len
+ 1) * sizeof(char)); if (palindrome == NULL) {
return NULL;
}
// 元の文字列をコピー
// 逆順に文字列を追加
for (int i = 0; i < len; i++) {
palindrome[len + i] = s[len - 1 - i];
}
// 末尾にヌル文字を追加
palindrome[new_len] = '\0';
return palindrome;
}
int main() {
char input[100];
// ユーザーから入力を受け取る
printf("文字列を入力してください(アルファベットのみ): ");
// 回文を生成
char *result = setPalindrome(input);
// 結果を表示
if (result != NULL) {
printf("生成された回文: %s\n", result
); // メモリの解放
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKLy8g5Zue5paH44KS55Sf5oiQ44GZ44KL6Zai5pWwCmNoYXIgKnNldFBhbGluZHJvbWUoY29uc3QgY2hhciAqcykgewogICAgLy8g5YWl5Yqb5paH5a2X5YiX44Gu6ZW344GV44KS5Y+W5b6XCiAgICBpbnQgbGVuID0gc3RybGVuKHMpOwogICAgCiAgICAvLyDmlrDjgZfjgYTmloflrZfliJfjga7plbfjgZXjgpLoqIjnrpfvvIjlhYPjga7mloflrZfliJfvvIvpgIbpoIbmloflrZfliJfvvIkKICAgIGludCBuZXdfbGVuID0gMiAqIGxlbjsKICAgIAogICAgLy8g5YuV55qE44Oh44Oi44Oq44Gu56K65L+dCiAgICBjaGFyICpwYWxpbmRyb21lID0gKGNoYXIgKiltYWxsb2MoKG5ld19sZW4gKyAxKSAqIHNpemVvZihjaGFyKSk7CiAgICBpZiAocGFsaW5kcm9tZSA9PSBOVUxMKSB7CiAgICAgICAgcHJpbnRmKCLjg6Hjg6Ljg6rjga7norrkv53jgavlpLHmlZfjgZfjgb7jgZfjgZ9cbiIpOwogICAgICAgIHJldHVybiBOVUxMOwogICAgfQogICAgCiAgICAvLyDlhYPjga7mloflrZfliJfjgpLjgrPjg5Tjg7wKICAgIHN0cmNweShwYWxpbmRyb21lLCBzKTsKICAgIAogICAgLy8g6YCG6aCG44Gr5paH5a2X5YiX44KS6L+95YqgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgcGFsaW5kcm9tZVtsZW4gKyBpXSA9IHNbbGVuIC0gMSAtIGldOwogICAgfQogICAgCiAgICAvLyDmnKvlsL7jgavjg4zjg6vmloflrZfjgpLov73liqAKICAgIHBhbGluZHJvbWVbbmV3X2xlbl0gPSAnXDAnOwogICAgCiAgICByZXR1cm4gcGFsaW5kcm9tZTsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIGlucHV0WzEwMF07CiAgICAKICAgIC8vIOODpuODvOOCtuODvOOBi+OCieWFpeWKm+OCkuWPl+OBkeWPluOCiwogICAgcHJpbnRmKCLmloflrZfliJfjgpLlhaXlipvjgZfjgabjgY/jgaDjgZXjgYTvvIjjgqLjg6vjg5XjgqHjg5njg4Pjg4jjga7jgb/vvIk6ICIpOwogICAgc2NhbmYoIiVzIiwgaW5wdXQpOwogICAgCiAgICAvLyDlm57mlofjgpLnlJ/miJAKICAgIGNoYXIgKnJlc3VsdCA9IHNldFBhbGluZHJvbWUoaW5wdXQpOwogICAgCiAgICAvLyDntZDmnpzjgpLooajnpLoKICAgIGlmIChyZXN1bHQgIT0gTlVMTCkgewogICAgICAgIHByaW50Zigi55Sf5oiQ44GV44KM44Gf5Zue5paHOiAlc1xuIiwgcmVzdWx0KTsKICAgICAgICAvLyDjg6Hjg6Ljg6rjga7op6PmlL4KICAgICAgICBmcmVlKHJlc3VsdCk7CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9Cg==