描述
有天小盼在学习英语课文的时候,看到了类似这样的句子:Miss white look it has a long nose and a short tail Sarah it has small eyes and big ear。单词之间用空格隔开(可能有多个空格),小盼突发奇想,想知道以d结尾的单词有几个,但是有些句子长度太长,他算不过来,你能帮帮他吗?
输入描述
开头一行,给出一段句子,句子长度为S(0<=S<=1000000)。
输出描述
开头一行,输出一个整数,代表以单词d结尾的单词个数
样例输入 1
Miss white look it has a long nose and a short tail Sarah it has small eyes and big ear
样例输出 1
2
样例输入 2
bird bird bird bird bird bird bird bird bird bird
样例输出 2
10
提示
【数据规模与约定】
百分比 | 范围 |
---|---|
%20 | S<=100 |
%60 | S<=10000 |
%100 | S=1000000 |
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(){
string a;
int sum = 0;
getline(cin,a);
for(int i = 0;i<a.size();i++){
if(a[i]==' '){
if(a[i-1]=='d'){
sum++;
}
}
}
cout<<sum;
return 0;
}