![]() |
#2
rjsp2013-03-05 08:43
|

#include<iostream>
using namespace::std;
int main(){
char first,second;
int ffcnt=0,flcnt=0,ficnt=0;
while(cin>>second){
if(first=='f'){
switch(second){
case 'f':
++ffcnt;
break;
case 'l':
++flcnt;
break;
case'i':
++ficnt;
break;
}
}first=second ;
}
cout<<"ff is "<<ffcnt<<endl;
cout<<"fl is "<<flcnt<<endl;
cout<<"fi is "<<ficnt<<endl;
return 0;
}
using namespace::std;
int main(){
char first,second;
int ffcnt=0,flcnt=0,ficnt=0;
while(cin>>second){
if(first=='f'){
switch(second){
case 'f':
++ffcnt;
break;
case 'l':
++flcnt;
break;
case'i':
++ficnt;
break;
}
}first=second ;
}
cout<<"ff is "<<ffcnt<<endl;
cout<<"fl is "<<flcnt<<endl;
cout<<"fi is "<<ficnt<<endl;
return 0;
}
这段统计双字符序列出现的次数的代码,
first应该理解为默认空格吗?
新手求解。