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. int len=myStrlen(s);
  15. tmp=(char *)malloc(sizeof(char)*(len*2+1));
  16. if(tmp==NULL)return 0;
  17. int i;
  18. for(i=0;i<len;i++){
  19. tmp[i]=s[i];
  20. }
  21. for(i=0;i<len;i++){
  22. tmp[len +i] = s[len- 1-i];
  23.  
  24. }
  25. tmp[len*2]='\0';
  26. return tmp;
  27.  
  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 0.01s 5284KB
stdin
abcd
stdout
abcd
  -> abcddcba