#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);
char *tmp
= (char *)malloc((2 * len
+ 1) * sizeof(char));
if (tmp == NULL) {
printf("Failed to allocate memory\n"); }
for (int i = 0; i < len; i++) {
tmp[i] = s[i];
}
for (int i = 0; i < len; i++) {
tmp[len + i] = s[len - i - 1];
}
tmp[2 * len] = '\0';
return tmp;
}
//メイン関数はいじる必要はありません
int main() {
char nyuryoku[1024]; // 入力
char *kaibun; // 回文を受け取る
kaibun = setPalindrome(nyuryoku);
printf("%s\n -> %s\n", nyuryoku
, kaibun
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSkgewogICAgaW50IGk7CiAgICBmb3IgKGkgPSAwOyBzW2ldICE9ICdcMCc7IGkrKyk7CiAgICByZXR1cm4gaTsKfQoKY2hhciAqc2V0UGFsaW5kcm9tZShjaGFyIHNbXSkgewogICAgaW50IGxlbiA9IG15U3RybGVuKHMpOyAKICAgIGNoYXIgKnRtcCA9IChjaGFyICopbWFsbG9jKCgyICogbGVuICsgMSkgKiBzaXplb2YoY2hhcikpOyAKCiAgICBpZiAodG1wID09IE5VTEwpIHsgCiAgICAgICAgcHJpbnRmKCJGYWlsZWQgdG8gYWxsb2NhdGUgbWVtb3J5XG4iKTsKICAgICAgICBleGl0KDEpOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbaV0gPSBzW2ldOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbbGVuICsgaV0gPSBzW2xlbiAtIGkgLSAxXTsKICAgIH0KCiAgICB0bXBbMiAqIGxlbl0gPSAnXDAnOwoKICAgIHJldHVybiB0bXA7IAp9CgovL+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