#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;
}
输入一串字符,统计ff,fl,fi出现的次数,为什么输入奇数个f就会出错啊?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- Eleven 2015-01-04 09: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; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作