练习5.12:修改统计元音字母的程序,使其能统计以下含有两个字符的字符序列的数量:ff、fl和fi。
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
unsigned ffCnt = 0, flCnt = 0, fiCnt = 0;
char ch, prech ='\0';
while (cin >> ch) {
bool bl=ture;
If(prech==‘f’)
{
\\此时switch中的ch已经是字符串的f后面的那个字符
switch (ch) {
case 'f':
++ffCnt;
Bl=false;
break;
case 'l':
++flCnt;
break;
case 'i':
++fiCnt;
break;
}
}
if(!bl)//如果bl等于false,重置prech,确保不会因为之前存在prech中f影响导致switch循环进行
prech=‘0’;
else
prech=ch;
}
cout<<ffCnt<<' '
<<flCnt<<' '
<<fiCnt<<' ';
system("pause");
return 0;
}