[NOIP popular group 2018] solution to a problem

T1: Title Statistics


Subject to the effect

Title Description

Kaikai just wrote a wonderful essay, the title of this essay I ask how many characters? Note: The title may contain upper and lower case letters, numbers, characters, spaces and line breaks. When the title character statistics, spaces and line breaks are not counted.

Input Format

Input file only one line, a string S .

Output Format

The output file is only one line containing an integer that is the number of characters essay title (no spaces and line breaks).

Sample input and output

Input # 1

234

Output # 1

3

Input # 2

like 45

Output # 2

4

Description / Tips

[O Sample 1 Description] title a total of 3 characters, these 3 characters are numeric characters.
[O Sample 2 illustrates] the title a total of 5 characters, including 1 uppercase letters, 1 lowercase letters and 2 numeric characters, and 1 spaces. Because spaces are not included in the result, the effective number of characters so the title is 4 Ge. 

[Data Size and agreed]
Predetermined | s | denotes the string s length (i.e., the character string and the number of spaces). 
For
40 % of the data, . 1 ≤ | S | ≤ . 5 , to ensure that the input line and the end line breaks numeric characters.
For
80 % of the data, 1 ≤ | S | ≤ 5 , the input may only contain upper and lower case letters, numeric characters and the end of the line newline.
For
100 % of the data, . 1 ≤ | S | ≤ . 5 , the input may include upper and lower case letters, numeric characters at the end, the line spaces and line breaks.

Thinking

Tl popularity, mainly on how to read the character string containing a space
First, we define a style string of a c [
. 11] reused gets () reads a character string traversal, if not spaces ans++ output answer ans

Code

#include <the iostream> 
#include <cstdio> // GET () library function where 
#include <CString> // strlen () library function where 
the using  namespace STD;
 int main () 
{ 
    int SUM = 0 ;
     char A [ . 11 ]; // C-style string 
    the gets (A); // use gets () function reads 
    for ( int I = 0 ; I <= strlen (A) - . 1 ; I ++) IF (A [I] =! '  ' ) SUM ++; // iterate 
    cout << SUM; // output answers
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/yjhqinghua/p/11402311.html
Recommended