描述
从键盘输入一个字符串(含空格),统计空格的个数。
输入描述
输入一个字符串,长度不超过1000;
输出描述
计算字符串中空格的个数,并输出
用例输入 1
There are 5 apples and 8 oranges
用例输出 1
6
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
int cnt = 0;
for(int i=0;i<=s.length();i++){
if(s[i]==' '){
cnt++;
}
}
cout<<cnt;
return 0;
}