fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int myStrlen(char w[]){
  5. int i;
  6. for(i=0;w[i]!='\0';i++);
  7. return i;
  8. }
  9.  
  10. // 関数の中でtmpに対してmallocして
  11. // そこに回文を代入してreturnで返しましょう
  12. char *setPalindrome(char w[]){
  13. int i,a;
  14. char *tmp;
  15. a=myStrlen(w);
  16. tmp=(char*)malloc(sizeof(char)*(a*2+1));
  17. if(tmp==NULL){
  18. printf("error");
  19. return 0;
  20. }
  21. for(i=0;i<a;i++)
  22. tmp[i]=w[i];
  23. for(i=0;i<a;i++)
  24. tmp[a+i]=w[a-i-1];
  25. tmp[2*a]='\0';
  26. return tmp;
  27. }
  28.  
  29.  
  30. //メイン関数はいじる必要はありません
  31. int main(){
  32. int i;
  33. char nyuryoku[1024]; //入力
  34. char *kaibun; //回文を受け取る
  35. scanf("%s",nyuryoku);
  36. kaibun = setPalindrome(nyuryoku);
  37. printf("%s\n -> %s\n",nyuryoku,kaibun);
  38. free(kaibun);
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5284KB
stdin
sa
stdout
sa
  -> saas