J - Vertical Histogram(1.5.7)

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


#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

int main()
{
    char s[100];
    int n=4;
    int cnt[27],i,j,len,m;
    memset(cnt,0,sizeof(cnt));
    while(n--)
    {

        memset(s,'0',sizeof(s));
        cin.getline(s,72,'\n');
        len = strlen(s)-1;
        for(i=0,j=0;i<=len;i++)
        {
            if(s[i]>='A'&&s[i]<='Z')
            {
                j = s[i] - 'A' + 1;
                cnt[j]++;   //统计每个字母出现的次数
            }
        }


    }
    //for(i=0;i<26;i++)        测试统计成功。。。
    //    cout<<cnt[i]<<' ' ;
    m = cnt[0];
    for(i=1;i<27;i++)
        m = m>cnt[i]?m:cnt[i];  //找出字母出现次数最多的一个字母,记下其次数
    //cout<<m<<endl;
    for(i=m;i>0;i--)    //输出有m行
    {
        for(j=1;j<26;j++)   //每一列判断该列字母出现次数是否与该行数值相等,若是则输出*,若否则输出空格
        {
            if(i==cnt[j])
            {
                cout<<"* ";  
                cnt[j]--;
            }
            else
                cout<<"  ";
        }
        if(i==cnt[j])          //单独输出最后一列,控制不必要的空格输出
            {
                cout<<"*";
                cnt[j]--;
            }
            else
                cout<<" ";
        cout<<endl;
    }
    cout<<"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"<<endl;//输出最底层字母行
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT研究僧大师兄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值