题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/4ec4325634634193a7cd6798037697a8

#include <iostream>

using namespace std;

int main() {
    string str1, str2;
    char m = ' ';
    while (getline(cin, str1)) {
        getline(cin, str2);
        for (int i = 0; i < str1.size(); i++) {
            int count = 0;
            if (str1[i] == '#') break;
            for (int j = 0; j < str2.size(); j++) {
                if (str1[i] == str2[j]) count++;
            }
            cout << str1[i] << m << count;
            printf("\n");
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务