华为机试1

写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

第一行输入一个有字母和数字以及空格组成的字符串,第二行输入一个字符。
输出输入字符串中含有该字符的个数。

诀窍:

  1. 使用count函数,#include
    count (InputIterator first, InputIterator last, const T& val);
    这个函数使用一对迭代器作为参数,查找范围在[first,last)之间的序列中元素val出现次数
    #include 
    using namespace std;
    
    int main(){
        string str="";
        getline(cin,str);
        char ch;
        cin>>ch;
        if((ch>='A') && (ch<='Z')){
            cout<='a') && (ch<='z')){
            cout<

     

你可能感兴趣的:(笔试)