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 totalLength = 2 * len;
  13. char *tmp = (char *)malloc((totalLength + 1) * sizeof(char));
  14.  
  15.  
  16. for (int i = 0; i < len; i++){
  17. tmp[i] = s[i];
  18. tmp[totalLength - 1 - i] = s[i];
  19. }
  20. tmp[totalLength] = '\0';
  21.  
  22. return tmp;
  23. }
  24.  
  25. int main(){
  26. int i;
  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. }
  35.  
Success #stdin #stdout 0s 5272KB
stdin
abcd
stdout
abcd
  -> abcddcba