计算字符个数

 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     char st[1000];
 6     char ch;
 7     int count = 0;
 8     memset(st,0,sizeof(st));
 9     gets(st);
10     ch = getchar();
11     if(ch >='a' && ch <='z')
12         ch = ch -'a'+'A';
13     for(int i = 0;st[i] != '';i++)
14     {
15         if(st[i] >= 'a' && st[i] <= 'z')
16             st[i] = st[i] -'a'+'A';
17         if(st[i] == ch)
18             count++;
19     }
20     printf("%d",count);
21 }

题目描述

写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。


输入描述:

输入一个有字母和数字以及空格组成的字符串,和一个字符。



输出描述:

输出输入字符串中含有该字符的个数。


输入例子:
ABCDEF
A

输出例子:
1
原文地址:https://www.cnblogs.com/ailx10/p/6287619.html