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. //以下に必要な宣言を含めて書いてください
  14. int t;
  15. t=myStrlen(s);
  16. char *tmp;
  17. tmp=malloc(sizeof(char)*(2*t));
  18. for(int k=0;k<t;k++){
  19. tmp[k]=s[k];
  20. }
  21. int k=1;
  22. for(int p=t;p<2*t;p++){
  23. tmp[p]=tmp[p-k];
  24. k=k+2;
  25.  
  26. }
  27. return tmp;
  28. }
  29.  
  30.  
  31. //メイン関数はいじる必要はありません
  32. int main(){
  33. int i;
  34. char nyuryoku[1024]; //入力
  35. char *kaibun; //回文を受け取る
  36. scanf("%s",nyuryoku);
  37. kaibun = setPalindrome(nyuryoku);
  38. printf("%s\n -> %s\n",nyuryoku,kaibun);
  39. free(kaibun);
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5280KB
stdin
abcd
stdout
abcd
  -> abcddcba