题解:P5015 [NOIP2018 普及组] 标题统计
cgy20140502 · · 题解
题意很容易明白,计算字符数就行了,难点是,不知去掉空格与换行,我用的是不定长输入,模版见下
while (cin >> a){
//做一些事情
}
可以把它搬到题目里,里面统计字母数。建立一个
while (cin >> s)
ans += s.length();
最后加上必要的。
AC代码
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int ans = 0;
while (cin >> s)
ans += a.length();//统计字母数量
cout << ans;
return 0;
}