a011: 幼稚園的算數遊戲

#include <stdio.h>

#define TRUE (1==1)
#define FALSE (0==1)
#define MAXLENGTH 1024

int func(char *s)
{
    int token = FALSE;
    int counter = 0;
    while(*s)
    {
        if(isalpha(*s++))
        {
            token = TRUE;
        }
        else
        {
            if(token == TRUE)
            {
                counter++;
                token = FALSE;
            }
        }
    }
    return counter;
}

main()
{
    char s[MAXLENGTH];
    while(fgets(s, MAXLENGTH, stdin))
    {
        printf("%d\n", func(s));
    }
    return 0;
}

留言