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. char *tmp;
  12. int len = myStrlen(s);
  13. int total = len * 2;
  14. tmp = (char *)malloc((total + 1) * sizeof(char));
  15. int i;
  16. for(i = 0; i < len; i++){
  17. tmp[i] = s[i];
  18. }
  19. for(i = 0; i < len; i++){
  20. tmp[len + i] = s[len - 1 - i];
  21. }
  22. tmp[total] = '\0';
  23. return tmp;
  24. }
  25.  
  26. int main(){
  27. char nyuryoku[1024];
  28. char *kaibun;
  29. scanf("%s", nyuryoku);
  30. kaibun = setPalindrome(nyuryoku);
  31. printf("%s\n -> %s\n", nyuryoku, kaibun);
  32. free(kaibun);
  33. return 0;
  34. }
Success #stdin #stdout 0s 5292KB
stdin
abcd
stdout
abcd
  -> abcddcba