题解 | #统计字符#

统计字符

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

#include "cstdio"
//#include "cstring"
#include "string.h"
#include "string"

using namespace std;

int main() {
    char buf[1024];
    while (fgets(buf, sizeof buf, stdin) != nullptr) {
        string cond1 = buf;
        buf[cond1.length() - 1] = '\0';
        if ('#' == buf[0]) {
            break;
        }
        cond1 = buf;
        fgets(buf, sizeof buf, stdin);
        string text = buf;
        buf[text.length() - 1] = '\0';
        text = buf;
        for (int i = 0; cond1[i] != '\0'; ++i) {
            int count = 0;
            for (int j = 0; text[j] != '\0'; ++j) {
                if (cond1[i] == text[j]) {
                    count++;
                }
            }
            printf("%c %d\n", cond1[i], count);
        }
    }
    return 0;
}

全部评论

相关推荐

龙珠传说:nb,公务员解约不需要支付违约金吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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