fork download
  1. # include <stdio.h>
  2.  
  3. int isPalindrome(char s[]){
  4.  
  5. int cnt=0;
  6. int st=0;
  7. int en=0;
  8.  
  9. for(int i=0;s[i]!='\0';i++){
  10. cnt++;
  11. }
  12.  
  13. en=cnt-1;
  14.  
  15. for(int i=0;i<=cnt-2;i++){
  16.  
  17. if(s[st]==s[en]){
  18. st++;
  19. en--;
  20. if(en==0) return 1;
  21. }
  22.  
  23. else break;
  24.  
  25. }
  26.  
  27. return 0;
  28. //関数の中だけを書き換えてください
  29. //回文になっているとき1を返す
  30. //回文になっていないとき0を返す
  31. }
  32.  
  33. //メイン関数は書き換えなくてよいです
  34. int main(){
  35. char s[100];
  36. scanf("%s",s);
  37. printf("%s -> %d\n",s,isPalindrome(s));
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5284KB
stdin
1147411
stdout
1147411 -> 1