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