fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* setPalindrome(const char* s) {
  6. int len = strlen(s);
  7.  
  8. char* palindrome = (char*)malloc(sizeof(char) * (len * 2 + 1));
  9.  
  10. if (palindrome == NULL) {
  11. return NULL;
  12. }
  13.  
  14. strcpy(palindrome, s);
  15.  
  16. for (int i = 0; i < len; i++) {
  17. palindrome[len + i] = s[len - 1 - i];
  18. }
  19.  
  20. palindrome[len * 2] = '\0';
  21.  
  22. return palindrome;
  23. }
  24.  
  25. int main() {
  26. char input[100];
  27.  
  28. scanf("%s", input);
  29.  
  30. char* result = setPalindrome(input);
  31.  
  32. if (result != NULL) {
  33. printf("作成された回文: %s\n", result);
  34.  
  35. free(result);
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 5288KB
stdin
 a d a da a s f 
stdout
作成された回文: aa