题解 | #计算某字符出现次数#

计算某字符出现次数

https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1

// HJ2 计算某字符出现次数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

class CharTimes {
public:
	void Times(string& str, string& s);
};

void CharTimes::Times(string& str, string& s)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (islower(str[i]))
		{
			str[i] = toupper(str[i]);
		}
	}
	if (islower(s[0]))
		s[0] = toupper(s[0]);
	int ans = 0;
	for (auto c : str)
	{
		if (s[0] == c)
			ans++;
	}
	cout << ans << endl;
}

int main()
{
	CharTimes a;
	string str, s;
	getline(cin, str);
	cin >> s;
	a.Times(str, s);
	return 0;
}

全部评论

相关推荐

mama3925:建议专业技能里测试移到最上面,加粗。然后适当加入些自动化测试工具。第二个项目,第三条亮点最后错别字。然后佬如果对自己很自信的话,可以项目放前面,然后项目里可以编造点测试经历,写在写在项目亮点的前两行。最后可加个自我评价,放个博客或者仓库链接
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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