题解 | #统计字符#感觉C++风格的输入比C风格的方便多了

统计字符

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

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

int main() {

    string str;
    string text;
    while (getline(cin, str)) { // 注意 while 处理多个 case
        if (str == "#") {
            break;
        }
        getline(cin, text);
        for (int i = 0; i < str.size(); i++) {
            int count = 0;
            for (int j = 0; j < text.size(); j++) {
                if (str[i] == text[j]) {
                    count++;
                }
            }
            printf("%c %d\n", str[i], count);
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
07-10 12:17
已编辑
商丘师范学院 Java
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务