#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[]){
char *tmp;
int i, len;
len = myStrlen(s);
// 回文の長さは元の文字列の長さ * 2 - 1 (中間の文字は重複)
tmp
= (char *)malloc((2 * len
) * sizeof(char)); // メモリ確保
// 元の文字列をコピー
for (i = 0; i < len; i++) {
tmp[i] = s[i];
}
// 逆順の文字列を追加(末尾から逆順に追加)
for (i = 0; i < len; i++) {
tmp[len + i] = s[len - i - 1];
}
tmp[2 * 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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCi8vIOaWh+Wtl+WIl+OBrumVt+OBleOCkuaxguOCgeOCi+mWouaVsAppbnQgbXlTdHJsZW4oY2hhciBzW10pewogICAgaW50IGk7CiAgICBmb3IoaT0wOyBzW2ldICE9ICdcMCc7IGkrKyk7CiAgICByZXR1cm4gaTsKfQoKLy8g5Zue5paH44KS55Sf5oiQ44GZ44KL6Zai5pWwCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pewogICAgY2hhciAqdG1wOwogICAgaW50IGksIGxlbjsKICAgIGxlbiA9IG15U3RybGVuKHMpOwogICAgCiAgICAvLyDlm57mlofjga7plbfjgZXjga/lhYPjga7mloflrZfliJfjga7plbfjgZUgKiAyIC0gMSAo5Lit6ZaT44Gu5paH5a2X44Gv6YeN6KSHKQogICAgdG1wID0gKGNoYXIgKiltYWxsb2MoKDIgKiBsZW4pICogc2l6ZW9mKGNoYXIpKTsgLy8g44Oh44Oi44Oq56K65L+dCiAgICAKICAgIC8vIOWFg+OBruaWh+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