【题目来源】
https://www.luogu.com.cn/problem/P5015
【题目描述】
凯凯刚写了一篇美妙的作文,请问这篇作文的标题中有多少个字符? 注意:标题中可能包含大、小写英文字母、数字字符、空格和换行符。统计标题字符数时,空格和换行符不计算在内。
【输入格式】
输入文件只有一行,一个字符串 ss。
【输出格式】
输出文件只有一行,包含一个整数,即作文标题的字符数(不含空格和换行符)。
【算法代码】
#include <bits/stdc++.h>
using namespace std;
int cnt=0;
int main() {
string s;
getline(cin,s);
for(int i=0;i<s.length();i++){
if(s[i]!=' ') cnt++;
}
cout<<cnt<<endl;
return 0;
}
/*
in:234
out:3
in:Ca 45
out:4
*/