fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int myStrlen(char s[]) {
  6. int i;
  7. for (i = 0; s[i] != '\0'; i++);
  8. return i;
  9. }
  10.  
  11. char *setPalindrome(char s[]) {
  12. int len = myStrlen(s);
  13. char *tmp;
  14.  
  15. tmp = (char*)malloc((2 * len + 1) * sizeof(char));
  16.  
  17. if (tmp == NULL) {
  18.  
  19. printf("Memory allocation failed\n");
  20. return NULL;
  21. }
  22.  
  23. for (int i = 0; i < len; i++) {
  24. tmp[i] = s[i];
  25. }
  26.  
  27. for (int i = 0; i < len; i++) {
  28. tmp[len + i] = s[len - 1 - i];
  29. }
  30.  
  31. tmp[2 * len] = '\0';
  32.  
  33. return tmp;
  34. }
  35.  
  36. int main(){
  37. int i;
  38. char nyuryoku[1024]; //入力
  39. char *kaibun; //回文を受け取る
  40. scanf("%s",nyuryoku);
  41. kaibun = setPalindrome(nyuryoku);
  42. printf("%s\n -> %s\n",nyuryoku,kaibun);
  43. free(kaibun);
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5276KB
stdin
abbe
stdout
abbe
  -> abbeebba