fork download
  1. # include <stdio.h>
  2.  
  3. int isPalindrome(char s[]){
  4. int len = 0;
  5. // 1. まず文字列の長さを数える(ぬるもじ '\0' まで)
  6. while(s[len] != '\0') {
  7. len++;
  8. }
  9.  
  10. // 2. 前(i)と後ろ(j)から挟み撃ちでチェック
  11. int i = 0;
  12. int j = len - 1; // 一番最後の文字の番号
  13.  
  14. while(i < j) {
  15. if(s[i] != s[j]) {
  16. return 0; // 一箇所でも違ったら回文じゃない
  17. }
  18. i++; // 前を一つ進める
  19. j--; // 後ろを一つ戻す
  20. }
  21.  
  22. return 1; // 最後まで一致したら回文!
  23. }
  24. int main(){
  25. char s[100];
  26. scanf("%s",s);
  27. printf("%s -> %d\n",s,isPalindrome(s));
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5320KB
stdin
girafarig
stdout
girafarig -> 1