Introduction to the design of NetEase cloud Classroom-C language _ Seventh week: pointer and string _1 Word length

Source: Internet
Author: User

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
1#include <stdio.h>2#include <string.h>3 4 Main ()5 {6     Charstr[ -];7     intCNT =0, I, len, n =0;8 gets (str);9 TenLen = (strlen (str));/*to find the length of a string str*/ One  A      for(i =0; i < len;i++)/*loop to judge every single character*/ -     { -         if((str[i]! =' ') && (str[i]! ='.'))/*when the character is not a space and not a., n++*/ the         { -n++; -         } -         Else        /*when the character is a space or a.*/ +         { -             if(n)/*if n is not 0*/ +             { A                 if(CNT)/*CNT After the second time, preceded by a space*/ at                 { -printf" "); -                 } -printf"%d", n);/*if n is not 0, output n*/ -cnt++;/*CNT After the second time, preceded by a space*/ -             } inn =0;/*when the character is a space or a., clear 0 N*/ -         } to     } +}

NetEase Cloud Classroom _ Programming Introduction-C language _ Seventh week: pointer and string _1 Word length

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.