#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 len_s;
int len_p;
int i,j;
len_s = myStrlen(s);
len_p = len_s * 2;
tmp
= (char *)malloc(sizeof(char) * (len_p
+ 1));
if (tmp == NULL) {
fprintf(stderr
, "メモリ確保に失敗しました。\n"); return NULL;
}
for (i = 0; i < len_s; i++) {
tmp[i] = s[i];
}
for (i = 0, j = len_s - 1; i < len_s; i++, j--) {
tmp[len_s + i] = s[j];
}
tmp[len_p] = '\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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpPTA7c1tpXSE9J1wwJztpKyspOwogICAgcmV0dXJuIGk7Cn0KY2hhciAqc2V0UGFsaW5kcm9tZShjaGFyIHNbXSl7CiAgICBjaGFyICp0bXA7CiAgICBpbnQgbGVuX3M7CiAgICBpbnQgbGVuX3A7CiAgICBpbnQgaSxqOwoKICAgIGxlbl9zID0gbXlTdHJsZW4ocyk7CiAgICAKICAgIGxlbl9wID0gbGVuX3MgKiAyOwoKICAgIHRtcCA9IChjaGFyICopbWFsbG9jKHNpemVvZihjaGFyKSAqIChsZW5fcCArIDEpKTsKICAgIAogICAgaWYgKHRtcCA9PSBOVUxMKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICLjg6Hjg6Ljg6rnorrkv53jgavlpLHmlZfjgZfjgb7jgZfjgZ/jgIJcbiIpOwogICAgICAgIHJldHVybiBOVUxMOwogICAgfQogICAgCiAgICBmb3IgKGkgPSAwOyBpIDwgbGVuX3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