POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)

Vertical Histogram
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 21223 Accepted: 10048
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<map>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
char a[100];
char  b[100];
char  c[100];
char  d[100];
int  ob[25];
int main()
{
    int ans=0;
    memset(ob,0,sizeof(ob));
    gets(a);
    gets(b);
    gets(c);
    gets(d);
    for(int i=0;i<100;i++){
    if(a[i]>='A'&&a[i]<='Z') ob[a[i]-'A'+1]++;
    if(b[i]>='A'&&b[i]<='Z') ob[b[i]-'A'+1]++;
    if(c[i]>='A'&&c[i]<='Z') ob[c[i]-'A'+1]++;
    if(d[i]>='A'&&d[i]<='Z') ob[d[i]-'A'+1]++;
    }
    for(int i=0;i<=26;i++)
    ans=max(ob[i],ans);
    for(int i=ans;i>=1;i--){
    for(int j=1;j<=26;j++)
    if(ob[j]>=i)cout<<"* ";
    else cout<<"  ";
    cout<<endl;
    }
    for(int j=0;j<=25;j++)
    {
        cout<<char(j+'A')<<' ';
    }
}

posted @ 2019-06-18 21:46  风骨散人  阅读(124)  评论(0编辑  收藏  举报