P5015 title Statistics

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 and output formats

Input formats:

 

Input file only one line, a string  S S.

 

Output formats:

 

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 Sample # 1:  Copy
234 
Output Sample # 1:  Copy
3
Input Sample # 2:  Copy
like 45 
Output Sample # 2:  Copy
4

Explanation

[O] Sample 1 shows
the title a total of three characters, three characters are numeric characters.

[O] Sample 2 shows the title a total of 5 five characters, including  1 1 uppercase letters,  1 1 lowercase letters and  2 two-numeric characters, and  1 one space. Because spaces are not included in the result, the effective number of characters in the title it is  4 4.

[Agreed] with the data size
specified  | s | | s | a string that represents  s length of s (that is, the number of spaces and the character string).
For  40 \% . 4 0 % of the data, . 1 ≤ | S | ≤. 5 . 1 | S | . 5, to ensure that the input line and the end line breaks numeric characters.
For  80 \% . 8 0 % of the data, . 1 ≤ | S | ≤. 5 . 1 | S | . 5, an input may only contain upper and lower case letters, numeric characters and line feed end of the line.
For  100 \% 1 0 0 % of the data, 1 ≤ | S | ≤ 5 1 | S | 5, the input may contain large, late lowercase letters, numbers, characters, spaces, line breaks and line.

#include<bits/stdc++.h>
using namespace std;
int ans;
int main(){
    string s;
    getline(cin,s);
    for(int i=0;i<s.size();++i){
        if(s[i]==' '||s[i]=='\n'){
            ans++;
        }
    }
    cout<<s.size()-ans; 
}

 

Guess you like

Origin www.cnblogs.com/crazily/p/11116317.html