解题报告2136

Vertical Histogram
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10243   Accepted: 4784

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
#include <iostream> #include <string> using namespace std; int main() { int count[26]={0}; string str[4];//,str_2,str_3,str_4; //cin>>str_1>>str_2>>str_3>>str_4; for (int i = 0;i < 4;i++) { getline(cin,str[i]); for (string::iterator it = str[i].begin();it != str[i].end();it++) if(*it>='A'&&*it<='Z') count[*it-'A']++; } int max = 0; for (int i = 0;i < 26;i++) { if(count[i]>max) max = count[i]; } char result[288][26] = {'/0'}; for (int i = 0;i < max;i++) { for (int j = 0;j < 26;j++) { if(i + count[j] >= max) result[i][j] = '*'; else result[i][j] = ' '; } } for (int i = 0;i < max;i++) { for (int j = 0;j < 26;j++) { cout<<result[i][j]; if (j < 25) { cout<<" "; } } cout<<endl; } for (int i = 0;i < 26;i++) { cout<<(char)('A'+i); if (i < 25) { cout<<" "; } } cout<<endl; }

你可能感兴趣的:(解题报告2136)