• POJ2136 Vertical Histogram【打印图案】


    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 19827   Accepted: 9483

    Description

    Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text input (no more than 72 characters per line) from the input file and print a vertical histogram that shows how many times each letter (but not blanks, digits, or punctuation) appears in the all-upper-case input. Format your output exactly as shown.

    Input

    * Lines 1..4: Four lines of upper case text, no more than 72 characters per line.

    Output

    * Lines 1..??: Several lines with asterisks and spaces followed by one line with the upper-case alphabet separated by spaces. Do not print unneeded blanks at the end of any line. Do not print any leading blank lines. 

    Sample Input

    THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
    THIS IS AN EXAMPLE TO TEST FOR YOUR
    HISTOGRAM PROGRAM.
    HELLO!
    

    Sample Output

                                *
                                *
            *                   *
            *                   *     *   *
            *                   *     *   *
    *       *     *             *     *   *
    *       *     * *     * *   *     * * *
    *       *   * * *     * *   * *   * * * *
    *     * * * * * *     * * * * *   * * * *     * *
    * * * * * * * * * * * * * * * * * * * * * * * * * *
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
    

    Source



    USACO 2003 February Orange


    问题链接POJ2136 Vertical Histogram

    问题简述:参见上述链接。

    问题分析

    统计四行输入的大写字母,根据统计结果输出柱状图。

    该问题的关键是需要一定的想象力,将统计数据转换成相应的图形。

    需要注意的一点是,如果出现次数最多字符的出现次数为max,则输出max行。这是关键的地方。

    程序说明:(略)


    AC的C++语言程序如下:

    /* POJ2136 Vertical Histogram */
    
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cctype>
    
    using namespace std;
    
    const int MAXN = 26;
    int acount[MAXN];
    
    int main()
    {
        int linecount, max;
        string s;
    
        memset(acount, 0, sizeof(acount));
    
        linecount = 0;
        while (getline(cin, s)) {
            // 统计字母
            for(int i=0; i<(int)s.size(); i++)
    //            if(isalpha(s[i]))
    //                acount[s[i] - 'A']++;
                if(isupper(s[i]))
                    acount[s[i] - 'A']++;
    
            // 每4行输出一次结果
            if(++linecount == 4) {
                linecount = 0;
    
                // 计算最大的统计值
                max = 0;
                for(int i=0; i<MAXN; i++)
                    if(acount[i] > max)
                        max = acount[i];
    
                // 输出max行
                for(int i=max; i>0; i--) {
                    for(int j=0; j<MAXN; j++) {
                        if(acount[j] >= i)
                            cout << "* ";
                        else
                            cout << "  ";
                    }
                    cout << endl;
                }
    
                for(int i=0; i<MAXN; i++)
                    cout << (char)('A' + i) << " ";
                cout << endl;
            }
        }
    
        return 0;
    }




  • 相关阅读:
    lua的多种实现方式(1-100的和)
    51单片机交通灯(定时器+38译码器+中断)
    51单片机定时器实现LED闪烁
    51单片机0号与1号外部中断实例
    51单片机:IO口扩展芯片用法(74HC165,74HC595)
    mybatis org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
    Intellij IDEA运行报Command line is too long解法
    Jmeter命令行运行实例讲解
    Windows10在当前目录快速打开cmd的方法
    Jmeter接口测试对json串中的值进行断言
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7563939.html
Copyright © 2020-2023  润新知