POJ 2136 Vertical Histogram

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17966   Accepted: 8681

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

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 80

using namespace std;

char s[MAX_N];
int ch[27];

int main(){
    memset(ch, 0, sizeof(ch));
    while(gets(s + 1)){
        int l = 0;
        l = strlen(s + 1);
        if(l == 0) break;
        REP(i, 1, l){
            if(s[i] >= 'A' && s[i] <= 'Z')
                ch[s[i] - 'A' + 1]++;
        }
    }
    int mx = 0;
    REP(i, 1, 26) mx = max(mx, ch[i]);
    REP_(i, 1, mx){ 
        REP(j, 1, 26){
            if(ch[j] < i) cout << "  ";
            else cout << "* ";
        }
        cout << endl;
    }
    REP(i, 1, 26) cout << (char)(65 + i - 1) << ' ';
    return 0;
} 

 


posted @ 2015-05-25 11:40  ALXPCUN  阅读(179)  评论(0编辑  收藏  举报