Cycle-06. Count the number of words in a single line of text (15) time limit MS Memory limit 65536 KB code length limit 8000 B award Program StandardAuthor Zhang Tong Hongyu (Zhejiang University)
This topic requires a program to count the number of words in a line of characters. The so-called "word" refers to a continuous string without spaces, separated by a space between the words, the number of spaces can be multiple.
Input format:
The input gives a line of characters.
Output format:
Outputs the number of words in a row.
Input Sample:
Let's go to the 209.
Sample output:
5
1#include <stdio.h>2#include <stdlib.h>3#include <math.h>4 intMain ()5 {6 Charstr[2];7 CharA;8 intCount =0;9 inti =0;Ten while(1) One { Ascanf"%c", &a); -Str[i%2] =A; - if(I >0&& str[i%2] ==' '&& str[(i-1)%2] !=' ') thecount++; -i++; - if(A = ='\ n') - Break; + } - if(Str[(i2)%2] ==' ') +printf"%d\n", count); A Else atprintf"%d\n", Count +1); - return 0; -}
Loop-06. Count the number of words in a line of text