首页 > 其他 > 详细

POJ 2136 Vertical Histogram

时间:2015-05-25 12:45:56      阅读:137      评论:0      收藏:0      [点我收藏+]
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;
} 

 


POJ 2136 Vertical Histogram

原文:http://www.cnblogs.com/ALXPCUN/p/4527479.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!