Luogu Brush Questions C++ Language | P5015 Title Statistics

Learn C++ from a baby! Record the questions in the process of Luogu C++ learning and test preparation, and record every moment.

Attached is a summary post: Luogu Brush Questions C++ Language | Summary


【Description】

Kai Kai just wrote a wonderful composition, how many characters are there in the title of this composition? Note: The title may contain uppercase and lowercase English letters, numeric characters, spaces and line breaks. Spaces and line breaks are not counted when counting title characters.

【enter】

The input file has only one line, a string  s .

【Output】

The output file has only one line, which contains an integer, which is the number of characters in the composition title (excluding spaces and newlines).

【Input example】

234

【Example of output】

3

【Code Explanation】

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ans=0;
    string s;
    getline(cin, s);
    ans = s.length();
    for (int i=0; i<s.length(); i++) {
        if (s[i]==' ') ans--;
    }
    cout << ans;
    return 0;
}

【operation result】

Ca 45
4

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132708112