#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 total_len = 2 * len;
char *tmp
= (char *)malloc((total_len
+ 1) * sizeof(char));
if (tmp == NULL)
{
fprintf(stderr
, "Memory allocation failed\n"); return NULL;
}
for (int i = 0; i < len; i++)
{
tmp[i] = s[i];
tmp[total_len - 1 - i] = s[i];
}
tmp[total_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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpID0gMDsgc1tpXSAhPSAnXDAnOyBpKyspOwogICAgcmV0dXJuIGk7Cn0KCmNoYXIgKnNldFBhbGluZHJvbWUoY2hhciBzW10pCnsKICAgIGludCBsZW4gPSBteVN0cmxlbihzKTsKICAgIGludCB0b3RhbF9sZW4gPSAyICogbGVuOwogICAgY2hhciAqdG1wID0gKGNoYXIgKiltYWxsb2MoKHRvdGFsX2xlbiArIDEpICogc2l6ZW9mKGNoYXIpKTsKCiAgICBpZiAodG1wID09IE5VTEwpCnsKICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIk1lbW9yeSBhbGxvY2F0aW9uIGZhaWxlZFxuIik7CiAgICAgICAgcmV0dXJuIE5VTEw7CiAgICAJCQkJCQl9CgoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspCnsKICAgICAgICB0bXBbaV0gPSBzW2ldOyAgICAgICAgICAgICAgIAogICAgICAgIHRtcFt0b3RhbF9sZW4gLSAxIC0gaV0gPSBzW2ldOwogICAgCQkJCQkJCQkJCX0KICAgIHRtcFt0b3RhbF9sZW5dID0gJ1ww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