#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 k=1,m = myStrlen(s);
for (int i = 0; i < m; i++) {
// 前半部分 s[0:i] と後半部分 s[m-i:m] が一致するかを確認
int match = 1;
for (int j = 0; j < m - i; j++) {
if (s[j] != s[m - 1 - j]) {
match = 0;
break;
}
}
// 完全に一致した場合
if (match) {
break;
}
}
tmp
= (char *)malloc(sizeof(char)* (2*m
+1)); if (tmp == NULL) {
return 0;}
for (int i = 0; i < m; i++) {
tmp[i] = s[i];}
for (int i = 0; i < m; i++) {
tmp[m+i] = s[m-1-i];}
tmp[2 * m]='\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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBteVN0cmxlbihjaGFyIHNbXSl7CiAgICBpbnQgaTsKICAgIGZvcihpPTA7c1tpXSE9J1wwJztpKyspOwogICAgcmV0dXJuIGk7Cn0KCi8vIOmWouaVsOOBruS4reOBp3RtcOOBq+WvvuOBl+OBpm1hbGxvY+OBl+OBpgovLyDjgZ3jgZPjgavlm57mlofjgpLku6PlhaXjgZfjgaZyZXR1cm7jgafov5TjgZfjgb7jgZfjgofjgYYKY2hhciAqc2V0UGFsaW5kcm9tZShjaGFyIHNbXSl7CgljaGFyICp0bXA7CgkvL+S7peS4i+OBq+W/heimgeOBquWuo+iogOOCkuWQq+OCgeOBpuabuOOBhOOBpuOBj+OBoOOBleOBhAoJaW50IGs9MSxtID0gbXlTdHJsZW4ocyk7CgkgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspIHsKICAgICAgICAvLyDliY3ljYrpg6jliIYgc1swOmldIOOBqOW+jOWNiumDqOWIhiBzW20taTptXSDjgYzkuIDoh7TjgZnjgovjgYvjgpLnorroqo0KICAgICAgICBpbnQgbWF0Y2ggPSAxOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbSAtIGk7IGorKykgewogICAgICAgICAgICBpZiAoc1tqXSAhPSBzW20gLSAxIC0gal0pIHsKICAgICAgICAgICAgICAgIG1hdGNoID0gMDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICAvLyDlrozlhajjgavkuIDoh7TjgZfjgZ/loLTlkIgKICAgICAgICBpZiAobWF0Y2gpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQogICAgdG1wID0gKGNoYXIgKiltYWxsb2Moc2l6ZW9mKGNoYXIpKiAoMiptKzEpKTsKICAgICAgIGlmICh0bXAgPT0gTlVMTCkgewogICAgICAgIHByaW50ZigiRVJST1JcbiIpOwogICAgICAgIHJldHVybiAwO30KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CiAgICAgICAgdG1wW2ldID0gc1tpXTt9CiAgICAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CiAgICAgICAgdG1wW20raV0gPSBzW20tMS1pXTt9CiAgICB0bXBbMiAqIG1dPSdcMCc7CiAgICByZXR1cm4gdG1wOwp9Ci8v44Oh44Kk44Oz6Zai5pWw44Gv44GE44GY44KL5b+F6KaB44Gv44GC44KK44G+44Gb44KTCmludCBtYWluKCl7CiAgICBpbnQgaTsKICAgIGNoYXIgbnl1cnlva3VbMTAyNF07IC8v5YWl5YqbCiAgICBjaGFyICprYWlidW47ICAgLy/lm57mlofjgpLlj5fjgZHlj5bjgosKICAgIHNjYW5mKCIlcyIsbnl1cnlva3UpOwogICAga2FpYnVuID0gc2V0UGFsaW5kcm9tZShueXVyeW9rdSk7CiAgICBwcmludGYoIiVzXG4gIC0+ICVzXG4iLG55dXJ5b2t1LGthaWJ1bik7CiAgICBmcmVlKGthaWJ1bik7CiAgICByZXR1cm4gMDsKfQo=