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 ;}