fork download
  1. # include <stdio.h>
  2.  
  3. int isPalindrome(char s[]){
  4. int right=0;
  5. int left=0;
  6.  
  7. // まず文字列の長さを調べる
  8. while(s[right] != '\0'){
  9. right++;
  10. }
  11. right--; // 最後の文字の位置へ
  12.  
  13. // 左右から比較
  14. while(left < right){
  15. if(s[left] != s[right]){
  16. return 0; // 回文ではない
  17. }
  18. left++;
  19. right--;
  20. }
  21.  
  22. return 1; // 回文
  23.  
  24.  
  25.  
  26.  
  27. //関数の中だけを書き換えてください
  28. //回文になっているとき1を返す
  29. //回文になっていないとき0を返す
  30. }
  31.  
  32. //メイン関数は書き換えなくてよいです
  33. int main(){
  34. char s[100];
  35. scanf("%s",s);
  36. printf("%s -> %d\n",s,isPalindrome(s));
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 5320KB
stdin
girafarig
stdout
girafarig -> 1