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. char *setPalindrome(char s[]) {
  11. int len = myStrlen(s);
  12. int i;
  13. char *tmp;
  14.  
  15. tmp = (char *)malloc((2 * len + 1) * sizeof(char));
  16. if (tmp == NULL) {
  17. printf("Memory allocation failed.\n");
  18. exit(1);
  19. }
  20.  
  21. for (i = 0; i < len; i++) {
  22. tmp[i] = s[i];
  23. }
  24.  
  25. for (i = 0; i < len; i++) {
  26. tmp[len + i] = s[len - 1 - i];
  27. }
  28.  
  29. tmp[2 * len] = '\0';
  30.  
  31. return tmp;
  32. }
  33.  
  34. int main() {
  35. char nyuryoku[1024];
  36. char *kaibun;
  37. scanf("%s", nyuryoku);
  38. kaibun = setPalindrome(nyuryoku);
  39. printf("%s\n -> %s\n", nyuryoku, kaibun);
  40. free(kaibun);
  41. return 0;
  42. }
  43.  
  44.  
Success #stdin #stdout 0s 5280KB
stdin
abcd
stdout
abcd
  -> abcddcba