HJ2题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <cctype> #include <iostream> #include <string> using namespace std; int main() { string str1; char exp; int num; getline(cin, str1);//getline是string的函数 cin.get(exp); exp = toupper(exp); for(int i=0; i<str1.length();i++) { str1[i] = toupper(str1[i]); if(str1[i] == exp) { (num)++; } } cout<<num; return 0; }
HJ2