题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include #include<string.h> using namespace std;
int main() { int count = 0; string str, temp1 = "", temp2 = ""; char c; getline(cin, str); cin >> c; for(int i = 0; i<str.size(); i++) { if(isdigit(c) != 0) { if(c == str[i]) { count++; } } else if (c == str[i] || int(c) == int(str[i])+32 || int(c) == int(str[i])-32) { count++; } } printf("%d", count); return 0; }