Kindergarten Counting Game
Everybody sit down in a circle. Ok. Listen to me carefully.
“Woooooo, you scwewy wabbit!”
Now, could someone tell me how many words I just said?
Input and Output
Input to your program will consist of a series of lines, each line containing multiple words (at least one). A “word” is defined as a consecutive sequence of letters (upper and/or lower case).
Your program should output a word count for each line of input. Each word count should be printed on a separate line.
Sample Input
Meep Meep! I tot I taw a putty tat. I did! I did! I did taw a putty tat. Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...
Sample Output
2 7 10 9
C Code
#include<stdio.h>
#include<string.h>
main()
{
int i,j,c,p=0,d,l;
while(gets(a))
{
c=0;
l=strlen(a);
p=0;
for(i = 0; i<l; i++)
{
d=0;
if(((a[i] >=97 && a[i] <= 122 )||(a[i] >=65 && a[i] <= 90)) && i != l-1)
continue;
else
{
for(j=i;j>=p;j--)
if((a[j] >= 97&& a[j] <= 122)||(a[j] >= 65 && a[j] <= 90))
{
d=1;
break;
}
if(d) c++;
p=i;
}
}
printf("%d\n",c);
}
return 0;
}