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.  
  11. char *setPalindrome(char s[]){
  12. char *tmp;
  13.  
  14. int i;
  15. int len = myStrlen(s);
  16. tmp = malloc(sizeof(char) * (len * 2 + 1));
  17. if(tmp == NULL)
  18. {
  19. printf("ERROR\n");
  20. return 0;
  21. }
  22.  
  23. int y = len;
  24. for(i=0; i<len; i++)
  25. {
  26. tmp[i]=s[i];
  27. }
  28.  
  29. for (int x = y-1; x>=0; x--)
  30. tmp[i++] = s[x];
  31.  
  32. tmp[i]= '\0';
  33.  
  34. return tmp;
  35.  
  36. }
  37.  
  38.  
  39. //メイン関数はいじる必要はありません
  40. int main(){
  41. int i;
  42. char nyuryoku[1024]; //入力
  43. char *kaibun; //回文を受け取る
  44. scanf("%s",nyuryoku);
  45. kaibun = setPalindrome(nyuryoku);
  46. printf("%s\n -> %s\n",nyuryoku,kaibun);
  47. free(kaibun);
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5296KB
stdin
abcd
stdout
abcd
  -> abcddcba