Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created October 28, 2009 02:11
Show Gist options
  • Save shaobin0604/220176 to your computer and use it in GitHub Desktop.
Save shaobin0604/220176 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
int main(void)
{
int c, nl, nc, nw, state;
nl = nc = nw = 0;
state = OUT;
while ((c = getchar()) != EOF)
{
nc++;
if (c == '\n')
nl++;
if (c == ' ' || c == '\t' || c == '\n')
state = OUT;
else if (state == OUT)
{
state = IN;
nw++;
}
}
printf("%d %d %d\n", nl, nw, nc);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment