fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *setPalindrome(char s[]){
  6. int length = strlen(s); //文字列の長さの取得
  7. char *pal = (char*)malloc(sizeof(char) * (2 * length));
  8.  
  9. if(pal == NULL)return NULL;
  10.  
  11. strcpy(pal, s); //文字列のコピー(s -> pal)
  12.  
  13. for(int i=0; i < length - 1; i++){
  14. *(pal + length + i) = s[length - 2 - i];
  15. }
  16. *(pal + 2 * length - 1) = '\0';
  17.  
  18. return pal;
  19. }
  20. int main(void){
  21. char enter[1024];
  22. scanf("%s", enter);
  23. char *result = setPalindrome(enter);
  24. printf("%s", result);
  25. free(result);
  26. return 0;
  27. }
Success #stdin #stdout 0s 5280KB
stdin
abc
stdout
abcba