PAT 06-3 words, pat06-3 words

Source: Internet
Author: User

PAT 06-3 words, pat06-3 words

This topic is simplified, with the question "ending with '.'" and "words have nothing to do with language ". In three cases, the input and output are

.-> NO output

A B.-> 1 1 (no space)

A B.-> 1 1 (no space)

In the program, a bool flag is set to ensure that no space is output at the end. When a number is output, the flag is set to true. When the next number is output, a space is output first, the question setting requirements and code implementation are as follows:

/* Name: Copyright: Author: Date: 31/03/15 Description: Your program needs to read a line of text, which is separated by spaces into several words and ends. You need to output the length of each word. The words here are irrelevant to the language and can contain various symbols. For example, "it's" is a word with a length of 4. Note that consecutive spaces may appear in the row. The last '.' is not included. Input Format: enter a line of text in a row, ending. Tip: Use scanf ("% c",...); to read a character until you read. Output Format: the length of the word corresponding to the line of text is output in a row. Each length is separated by a space. There is no final space at the end of the line. Input example: It's great to see you here. output example: 4 5 2 3 3 4 */# include <stdio. h> # include <stdbool. h> int main () {// freopen ("in.txt", "r", stdin); // for test char ch; int cnt; bool flag; flag = false; cnt = 0; while (ch = getchar () & ch! = '.') {If (ch! = '') Cnt ++; else if (cnt! = 0) {if (flag) printf (""); printf ("% d", cnt); flag = true; cnt = 0 ;}} if (cnt! = 0) {if (flag) printf (""); printf ("% d \ n", cnt) ;}// fclose (stdin ); // for test return 0 ;}

 

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.