计算字符个数,C++

计算字符个数

http://www.nowcoder.com/questionTerminal/a35ce98431874e3a820dbe4b2d0508b1

计算字符个数:C++;利用getchar函数读取带空格的字串符
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
char ch[5000];
char s;
int i = 0;
while ((ch[i] = getchar())&&(ch[i]!='\n'))
{
i++;
}
cin >> s;
if (s >= 'A' && s <= 'Z')s += 32;
int num = 0;
for (int j = 0;j < i;j++)
{
if (ch[j] >= 'A' && ch[j] <= 'Z')ch[j] += 32;
if (ch[j] == s)num++;
}
cout << num << endl;
}</string></iostream>

全部评论

相关推荐

01-12 20:31
东北大学 Java
点赞 评论 收藏
分享
迷茫的大四🐶:不是,匿名发帖,你也可以发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务