#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 newLen = len * 2;
char *tmp
= (char *)malloc((newLen
+ 1) * sizeof(char));
if (tmp == NULL) {
return NULL;
}
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[newLen] = '\0';
return tmp;
}
int main() {
char nyuryoku[1024];
char *kaibun;
kaibun = setPalindrome(nyuryoku);
printf("%s\n -> %s\n", nyuryoku
, kaibun
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpID0gMDsgc1tpXSAhPSAnXDAnOyBpKyspOwogICAgcmV0dXJuIGk7Cn0KCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pIHsKICAgIGludCBsZW4gPSBteVN0cmxlbihzKTsKICAgIGludCBuZXdMZW4gPSBsZW4gKiAyOwogICAgY2hhciAqdG1wID0gKGNoYXIgKiltYWxsb2MoKG5ld0xlbiArIDEpICogc2l6ZW9mKGNoYXIpKTsgCgogICAgaWYgKHRtcCA9PSBOVUxMKSB7IAogICAgICAgIHJldHVybiBOVUxMOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbaV0gPSBzW2ldOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICB0bXBbbGVuICsgaV0gPSBzW2xlbiAtIGkgLSAxXTsKICAgIH0KCiAgICB0bXBbbmV3TGVuXSA9ICdcMCc7IAogICAgcmV0dXJuIHRtcDsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIG55dXJ5b2t1WzEwMjRdOyAKICAgIGNoYXIgKmthaWJ1bjsgICAgICAgCiAgICBzY2FuZigiJXMiLCBueXVyeW9rdSk7CiAgICBrYWlidW4gPSBzZXRQYWxpbmRyb21lKG55dXJ5b2t1KTsKCiAgICBwcmludGYoIiVzXG4gIC0+ICVzXG4iLCBueXVyeW9rdSwga2FpYnVuKTsKICAgIGZyZWUoa2FpYnVuKTsKICAgIHJldHVybiAwOwp9Cg==