fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int myStrlen(char s[]){
  5. int i;
  6. for(i=0;s[i]!='\0';i++);
  7. return i;
  8. }
  9.  
  10. // 関数の中でtmpに対してmallocして
  11. // そこに回文を代入してreturnで返しましょう
  12. char *setPalindrome(char s[]){
  13. char *tmp;
  14. //以下に必要な宣言を含めて書いてください
  15. int len = myStrlen(s);
  16. tmp = (char*)malloc(sizeof(char)*(len*2+1)); //len*2+1文字のスペース
  17. if(tmp ==NULL) return NULL;
  18.  
  19. for(int x = 0; x<len; x++){
  20. tmp[x] = s[x];
  21. }
  22. for(int x=0; x<len; x++){
  23. tmp[len + x] = s[len - 1 - x];
  24. }
  25. tmp[len*2] ='\0'; //文字列の終わり
  26.  
  27. return tmp;
  28. }
  29. //メイン関数はいじる必要はありません
  30. int main(){
  31. int i;
  32. char nyuryoku[1024]; //入力
  33. char *kaibun; //回文を受け取る
  34. scanf("%s",nyuryoku);
  35. kaibun = setPalindrome(nyuryoku);
  36. printf("%s\n -> %s\n",nyuryoku,kaibun);
  37. free(kaibun);
  38. return 0;
  39. }
Success #stdin #stdout 0s 5308KB
stdin
asd
stdout
asd
  -> asddsa