fork download
  1. #include <stdio.h>
  2.  
  3. int isPalindrome(char s[]){
  4. int length = 0;
  5.  
  6. // 文字列の長さを自分で数える
  7. while (s[length] != '\0') {
  8. length++;
  9. }
  10.  
  11. int left = 0;
  12. int right = length - 1;
  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. // メイン関数(そのままでOK)
  26. int main(){
  27. char s[100];
  28. scanf("%s",s);
  29. printf("%s -> %d\n",s,isPalindrome(s));
  30. return 0;
  31. }
  32.  
  33.  
Success #stdin #stdout 0.01s 5284KB
stdin
girafarig
stdout
girafarig -> 1