fork(1) 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. // 関数の中でtmpに対してmallocして
  11. // そこに回文を代入してreturnで返しましょう
  12. char *setPalindrome(char s[]){/*s=入力した文字列*/
  13. char *tmp;
  14. //以下に必要な宣言を含めて書いてください
  15. int len = myStrlen(s);
  16. int y = len;//最後の文字
  17. tmp = malloc(sizeof(char) * len * 2 - 1);//末尾の文字-1
  18. int count = sizeof(tmp)-1;
  19. char tmp_copy[sizeof(tmp)];
  20.  
  21. for(int i=0; i<sizeof(tmp); i++) tmp_copy[i]=tmp[i];
  22.  
  23. for(int i=0; i<len; i++){
  24. tmp[count]=tmp_copy[i];
  25. count--;
  26. }
  27. return tmp;
  28. }
  29.  
  30.  
  31. //メイン関数はいじる必要はありません
  32. int main(){
  33. int i;
  34. char nyuryoku[1024]; //入力
  35. char *kaibun; //回文を受け取る
  36. scanf("%s",nyuryoku);
  37. kaibun = setPalindrome(nyuryoku);
  38. printf("%s\n -> %s\n",nyuryoku,kaibun);
  39. free(kaibun);
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5304KB
stdin
abcd
stdout
abcd
  ->