Cycle-06. Count the number of words in a line of text

Source: Internet
Author: User

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

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.