fork download
  1. #include <stdio.h>
  2.  
  3. int isPalindrome(char s[]) {
  4. int left = 0;
  5. int right = 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. int main() {
  26. char s[100];
  27. scanf("%s", s);
  28. printf("%s -> %d\n", s, isPalindrome(s));
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5284KB
stdin
repaper
stdout
repaper -> 1