输入一串字符, 统计特定字符个数

include < stdio.h >
include < iostream >
include < string >
int main(int argc, char **argv)
{
        int a = 0, b = 0, c = 0;
        string str;
        getline(cin, str);

        for(auto it = str.begin(); it != str.end(); ++it){
                if (*it == 'a')a++;
                else if (*it == 'b')b++;
                else if (*it == 'c')c++;
        }
        printf ("There are %d a, %d b and %d c\n", a, b, c);
    return 0;
}
posted @ 2014-07-18 21:07  wu_overflow  阅读(283)  评论(0编辑  收藏  举报