7-6打卡

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;
}

posted @ 2023-07-06 20:08  aallofitisst  阅读(13)  评论(0)    收藏  举报