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. int len = myStrlen(s);
  13. int total = len * 2;
  14. char *tmp = malloc(total + 1);
  15.  
  16. int i;
  17.  
  18.  
  19. for(i = 0; i < len; i++){
  20. tmp[i] = s[i];
  21. }
  22.  
  23.  
  24. for(i = 0; i < len; i++){
  25. tmp[len + i] = s[len - 1 - i];
  26. }
  27.  
  28.  
  29. tmp[total] = '\0';
  30.  
  31. return tmp;
  32. }
  33.  
  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. }
  46.  
Success #stdin #stdout 0.01s 5324KB
stdin
hgfjh
stdout
hgfjh
  -> hgfjhhjfgh