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. // メイン関数:書き換えなくてよい
  26. int main() {
  27. char s[100];
  28. scanf("%s", s);
  29. printf("%s -> %d\n", s, isPalindrome(s));
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5328KB
stdin
shinbunshi
stdout
shinbunshi -> 0