C++ 输入一行字符串,统计其中字符'a'的个数。 输出要求: 只有一个整 ...

发布网友 发布时间:1天前

我来回答

1个回答

热心网友 时间:3分钟前

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str;
    cin >> str;

    size_t pos;
    int count = 0;
    while (string::npos != (pos = str.find('a', pos)))
    {
        count++;
        pos++;
    }

    cout << count << endl;

    return 0;
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com