u011585252 于 2014.10.17 10:43 提问

#include
#include
using namespace std;
int main()
{
int a=0,b=0,c=0;
char aa,bb=' ';
vector ss;
while(cin.get(aa))
{
ss.push_back(aa);
}
for(vector::iterator i=ss.begin();i!=ss.end();++i)
{
if(bb=='f')
{
switch(*i)
{
case 'f':
++a;
break;
case 'l':
++b;
break;
case 'i':
++c;
break;
}
++i;
}
bb=*i;
}
cout<<"the number of ff is:"<<a<<endl;
cout<<"the number of fl is:"<<b<<endl;
cout<<"the number of fi is:"<<c<<endl;
system("pause");
return 0;
}

1个回答

VisualEleven      2015.01.04 17:31
`````` #include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
int a=0,b=0,c=0;
string aa;
char bb=' ';
vector<char> ss;

cin>>aa;

for(string::size_type i = 0; i != aa.size(); ++i)
{
ss.push_back(aa.at(i));
}
for(vector<char>::iterator i=ss.begin();i!=ss.end();++i)
{
if(bb=='f')
{
switch(*i)
{
case 'f':
++a;
break;
case 'l':
++b;
break;
case 'i':
++c;
break;
}
++i;
}
bb=*i;
}
cout<<"the number of ff is:"<<a<<endl;
cout<<"the number of fl is:"<<b<<endl;
cout<<"the number of fi is:"<<c<<endl;
system("pause");
return 0;
}
``````