7-6打卡

wlxdaydayup / 2023-07-06 / 原文

pta第三题
统计1000以内数字个数
用map容器即可实现,每个数字为key,它们出现次数为value,而数字可以用字符串来存储
代码实现

#include <iostream>
#include <map>

int main() {
    std::string N;
    std::cin >> N;

    std::map<char, int> digitCount;

    for (char digit : N) {
        digitCount[digit]++;
    }

    for (const auto& pair : digitCount) {
        std::cout << pair.first << ":" << pair.second << std::endl;
    }

    return 0;
}