7-102 3009 垂直直方图

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using pii = std::pair<i32, i32>;
using pll = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vll = std::vector<i64>;
using vpii = std::vector<pii>;
using vpll = std::vector<pll>;

void solve();

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

void solve()
{
    std::string str;
    vi data(27, 0);
    for (i32 i = 1; i <= 4; ++i)
    {
        std::getline(std::cin, str);
        for (auto &i : str)
        {
            if (std::isalpha(i))
            {
                ++data[i - 'A' + 1];
            }
        }
    }
    i32 max = std::numeric_limits<i32>::min();
    for (auto &item : data)
    {
        max = std::max(item, max);
    }
    for (i32 i = 1; i <= max; ++i)
    {
        bool space = false;
        i32 back;
        for (i32 j = 26; j >= 1; --j)
        {
            if (data[j] >= max - i + 1)
            {
                back = j;
                break;
            }
        }
        for (i32 j = 1; j <= back; ++j)
        {
            if (space)
            {
                std::cout << ' ';
            }
            if (data[j] >= max - i + 1)
            {
                std::cout << '*';
            }
            else
            {
                std::cout << ' ';
            }
            space = true;
        }
        std::cout << std::endl;
    }

    bool space = false;
    for (i32 i = 0; i < 26; ++i)
    {
        if (space)
        {
            std::cout << ' ';
        }
        std::cout << static_cast<char>('A' + i);
        space = true;
    }
}
posted @ 2025-10-13 08:22  TPPPP72  阅读(8)  评论(0)    收藏  举报