fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int myStrlen(char s[])
  5. {
  6. int i;
  7. for(i=0;s[i]!='\0';i++);
  8. return i;
  9. }
  10.  
  11. // 関数の中でtmpに対してmallocして
  12. // そこに回文を代入してreturnで返しましょう
  13. char *setPalindrome(char s[])
  14. {
  15. int i,j,count = myStrlen(s);
  16. char *tmp;
  17. tmp = (char*)malloc(sizeof(char)*(2*count+1));
  18. for(i=0;s[i]<count;i++)
  19. {
  20. tmp[i] = s[i];
  21. }
  22. for(i=0;i<count;i++)
  23. {
  24. tmp[count+i] = s[count-1-i];
  25. }
  26. tmp[2 * count] = '\0';
  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 5288KB
stdin
abcd
stdout
abcd
  ->