把输入的字符串和字符都变成大写或小写,然后逐一计数
#include
#include
#include
#include
using namespace std;
int main() {
string s;
char c;
getline(cin, s);
cin >> c;
int len = s.length();
transform(s.begin(), s.end(), s.begin(), ::tolower);
c = tolower(c);
int ans = 0;
for (int i = 0; i < len; i++) {
if (c == s[i]) ans++;
}
cout << ans << endl;
}
transform(s.begin(), s.end(), s.begin(), ::tolower);
transform(s.begin(), s.end(), s.begin(), ::toupper);
c = tolower(c); c = toupper(c);