题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
//https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1?tpId=37&tqId=21225&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title= #include <iostream> #include <iostream> using namespace std; int main() { string s, s0; while (getline(cin, s)) { //注意输入字符串的格式 int sum = 0; for(auto &c:s) //注意引用的使用 if(islower(c)) c-=('a'-'A'); getline(cin, s0); if(islower(s0[0])) s0[0]-=('a'-'A'); for(auto c:s) if(s0[0]==c) sum++; cout << sum; } }