POJ 2136 Vertical Histogram 水

来源:互联网 发布:莆田广电网络客服电话 编辑:程序博客网 时间:2024/05/09 07:01


Vertical Histogram

Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 18152 Accepted: 8764

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 YOURHISTOGRAM 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

AC代码:

#include <iostream>#include <cstring>#include <cctype>#include <algorithm>using namespace std;int map[26];int maxc=-1,t;string a="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";void my(string in){    int len=in.length();    for(int i=0;i<len&&i<72;++i){        if(isupper(in[i]))            map[(in[i]-65)]++;    }}void fun(int i,int j){    int t=i+1;    t=10-t;    int ok=0;    for(int k=j+1;k<26;++k)if(map[k]>maxc-i-1)ok=1;    if(ok)cout<<"  ";    /*for(int k=j;k<26;++k){        if(map[k]>t){            cout<<" -";            return;        }    }*/}void fun2(int i,int j){    if(j<t){        cout<<' ';        return;    }    int ok=0;    for(int k=j+1;k<26;++k)if(map[k]>maxc-i-1)ok=1;    if(ok)cout<<' ';}int main(){    string in[4];    memset(map,0,sizeof(map));    for(int i=0;i<4;++i){        getline(cin,in[i]);        my(in[i]);    }    for(int i=0;i<26;++i)        if(maxc<map[i]){            maxc=map[i];            t=i;        }    int h=maxc;    for(int i=0,k=26;i<h;i++,k--){        for(int j=0;j<26;++j){            if(map[j]==maxc){                cout<<"*";                fun2(i,j);            }            else if(map[j]+i>=maxc){                cout<<"*";                fun2(i,j);            }            else if(j<t){                cout<<" ";                fun2(i,j);            }            else fun(i,j);        }        cout<<'\12';    }    cout<<a<<'\12';    /**    for(int i=0;i<26;i++)cout<<map[i]<<' ';    /**/    return 0;}

0 0