fork(1) download
  1. # include <stdio.h>
  2.  
  3. int isPalindrome(char s[]){
  4. //関数の中だけを書き換えてください
  5. //回文になっているとき1を返す
  6. //回文になっていないとき0を返す
  7. int i = 0;
  8. int len = 0;
  9.  
  10. // 文字列の長さを求める
  11. while (s[len] != '\0') {
  12. len++;
  13. }
  14.  
  15. // 前と後ろから比較
  16. for (i = 0; i < len / 2; i++) {
  17. if (s[i] != s[len - 1 - i]) {
  18. return 0; // 回文ではない
  19. }
  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 5312KB
stdin
girafarig
stdout
girafarig -> 1