2011年12月27日 星期二

C acm494 kindergarten counting game

 [心得]  //runtime 0.004
 1.ctype.h 的函數 isalpha() 測試參數是否為字母,滿足條件回傳非 0 的值,否則回傳 0 。
 2.如果Array size 設定太小,就會ㄧ直 Wrong Answer!

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
    char s[1000];
    int i;
    int counter =0;
    while(fgets(s,sizeof(s),stdin)!=NULL)  // 可以換成while(gets(s)){  ....}
    {
     counter=0;
     for(i =0;s[i]!='\0';i++){
         if(isalpha(s[i])>0 && isalpha(s[i+1])==0)
           counter ++;
     }
     printf("%d\n",counter);       
    }
  
  
     system("pause");
    //return 0;
}

沒有留言:

張貼留言