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