code4sk/c/sourcecode/朱森森带领的奇妙冒险/字符串1/统计字符出现次数.cpp
2023-10-18 16:17:32 +08:00

34 lines
533 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//统计字符出现次数
//本题要求编写程序,统计并输出某给定字符在给定字符串中出现的次数。
//输入格式:
//输入第一行给出一个以回车结束的字符串少于80个字符第二行输入一个字符。
//输出格式:
//在一行中输出给定字符在给定字符串中出现的次数。
//输入样例:
//programming is More fun!
//m
//输出样例:
//2
#include<stdio.h>
#include<string.h>
int main(){
int i,count=0;
char str[81];
gets(str);
char c;
scanf("%c",&c);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==c)
count++;
}
printf("%d\n",count);
return 0;
}