本题要求编写程序,统计并输出某给定字符在给定字符串中出现的次数。
输入格式:
输入第一行给出一个以回车结束的字符串(少于80个字符);第二行输入一个字符。
输出格式:
在一行中输出给定字符在给定字符串中出现的次数。
输入样例:
programming is More fun!
m
输出样例:
2
#include
using namespace std;
#define max 80
int main()
{
char c[max],ch,ch1,i=0,j,count=0;
do{
ch=cin.get();
c[i]=ch;
i++;
}while(ch!='\n');
cin>>ch1;
for(j=0;j<i;j++)
{
if(c[j]==ch1)
count++;
}
cout<<count;
}