您的位置:首页 > 其它

Vertical Histogram垂直直方图

2015-08-19 16:54 411 查看
E - Vertical Histogram
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u

Submit

Status

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
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int maxn=-1;
    string s;
    int cnt[30];
    memset(cnt,0,sizeof(cnt));
    for(int i=0; i<4; i++)
    {
        getline(cin,s);
        for(int j=0; j<s.length(); j++)
            if(isupper(s[j]))
                cnt[s[j]-'A']++;
    }
    for(int i=0; i<26; i++)
        if(cnt[i]>maxn)
            maxn=cnt[i];
    for(int i=0; i<maxn; i++)
    {
        for(int j=0; j<26; j++)
            if(cnt[j]>=maxn-i)
                printf("* ");
            else
                printf("  ");
        puts("");
    }
    for(int i=0; i<26; i++)
        printf("%c ",'A'+i);
    puts("");
    return 0;
}
//string s的输入用getline(cin,s),长度为s.length(),并且此时的getline(cin,s)可以用gets(s)代替
//char s的输入用gets(s),长度为strlen(s)

运行结果:



学习心得:这个题挺有趣的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: