|
|
1.1 ! root 1: #print ! 2: Write a program which counts the number of five letter ! 3: words in its input (define a word as anything between ! 4: blanks, tabs or newlines). Compile and run it, then type "ready". ! 5: Note that all that is wanted is the total number of ! 6: five letter words - nothing was said about distinct ! 7: words. Just count the number of times exactly five ! 8: characters appear between spaces. ! 9: #once #create Ref ! 10: This is a passage of text which contains ! 11: exactly twelve words of five letters. ! 12: Words may appear at the start or at the final ! 13: part of a line. Other words show up in ! 14: the middle. Avoid counting seven or eight letters ! 15: but every five must be noted. ! 16: #user ! 17: a.out <Ref >xxx ! 18: grep 12 xxx >/dev/null ! 19: #succeed ! 20: /* one way to count five letter words */ ! 21: #include <stdio.h> ! 22: ! 23: main() ! 24: { ! 25: int since, wdnum, c; ! 26: ! 27: since = 0; ! 28: while ((c=getchar()) != EOF) { ! 29: if (c == ' ' || c == '\t' || c == '\n') { ! 30: if (since == 5) ! 31: wdnum++; ! 32: since = 0; ! 33: } ! 34: else ! 35: since++; ! 36: } ! 37: printf("%d\n", wdnum); ! 38: } ! 39: #log ! 40: #next ! 41: 15.1a 10
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.