home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume17
/
contest-prog
/
part02
/
prob5.txt
< prev
next >
Wrap
Text File
|
1989-02-06
|
1KB
|
33 lines
Problem 5: count the number of words in a text file.
The input file will consist of some number of lines.
There will be only lowercase letters and blanks (and of course,
newlines) in the input file. (I.e., no tabs).
Each line will have zero or more non-blank strings separated
by one or more blanks. Leading blanks are permitted in the input file.
A "word" is defined as a "string which does not contain a blank".
Your program should produce exactly as many lines as there are
lines in the input file. Your output should be the integer number
representing the number of "words" on the corresponding input line.
Example: if the input file consists of exactly six lines:
now is the time
for all
thirty days hath
september
testing testing cqcqcq de k4xe
Then your output would be
4
2
3
1
0
5
<this line is not part of your output>
Pay particular attention to the fact that a blank line should
produce a zero-count in your output file. To emphasize:
You should produce some output for each line of input, even if
it is totally blank.