1 Word Length (4 points)
Topic content:
Your program reads a line of text, separated by a space into several words, to '. ' End. You want to output the length of each word in this line of text. The words here are not language-related, and can include various symbols, such as "it's" to count a word, length 4. Note that there may be contiguous spaces in the row.
Input format:
Enter a line of text in a row to '. ' End, the ending period cannot be counted within the length of the last word.
Output format:
Prints the length of the word for the line text in a row, separated by a space between each length, with no last space at the end of the line.
Input Sample:
It's great to see your here.
Sample output:
4 5 2 3 3 4
Time limit: 500ms memory limit: 32000kb
Reference Code
#include <stdio.h>int main () {char x[100];//input character int i=0;int j=0;//int size;int cnt=0;printf ("Input some strings\n" );//SCANF ("%c", &x[i]);//1<=i<=3while (x[i-1]!= '. ') {scanf ("%c", &x[i]); i++;} 123 AB abc.for (j=0;j<i;j++) {if (x[j]!= ' && x[j]!= '. ') {cnt++;//continue;} else if (x[j]== ' && x[j-1]!= ')//First time space is printed {printf ("%d", CNT); cnt=0;//continue;} else if (x[j]== '. ') {printf ("%d", CNT); break;}} return 0;}
Chinese University Mooc | Introduction to C language Programming 8th week programming Practice Onge