#include <stdio.h>
#include <stdlib.h>
int myStrlen(char s[]) {
int i;
for (i = 0; s[i] != '\0'; i++);
return i;
}
// 関数の中でtmpに対してmallocして
// そこに回文を代入してreturnで返しましょう
char* setPalindrome(char s[]) {
char* tmp;
//以下に必要な宣言を含めて書いてください
int num = myStrlen(s);
int j,k=1;
tmp
= (char*)malloc(sizeof(char) * num
* 2); if(tmp==NULL){
return 0;
}
for ( j = 0; j <= num - 1; j++) {
tmp[j] = s[j];
}
for (j = num; j <= num * 2-1; j++ ) {
tmp[j] = s[num - k];
k++;
if(tmp[num*2]=tmp[0]){
tmp[num*2]='\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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSkgewoJaW50IGk7Cglmb3IgKGkgPSAwOyBzW2ldICE9ICdcMCc7IGkrKyk7CglyZXR1cm4gaTsKfQoKLy8g6Zai5pWw44Gu5Lit44GndG1w44Gr5a++44GX44GmbWFsbG9j44GX44GmCi8vIOOBneOBk+OBq+WbnuaWh+OCkuS7o+WFpeOBl+OBpnJldHVybuOBp+i/lOOBl+OBvuOBl+OCh+OBhgpjaGFyKiBzZXRQYWxpbmRyb21lKGNoYXIgc1tdKSB7CgljaGFyKiB0bXA7CgoJLy/ku6XkuIvjgavlv4XopoHjgarlrqPoqIDjgpLlkKvjgoHjgabmm7jjgYTjgabjgY/jgaDjgZXjgYQKCWludCBudW0gPSBteVN0cmxlbihzKTsKCWludCBqLGs9MTsKCXRtcCA9IChjaGFyKiltYWxsb2Moc2l6ZW9mKGNoYXIpICogbnVtICogMik7CglpZih0bXA9PU5VTEwpewoJCXByaW50ZigiRVJST1IiKTsKCQlyZXR1cm4gMDsKCX0KCWZv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