zoukankan      html  css  js  c++  java
  • Vertical Histogram

    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 <string.h>
    using namespace std;
    int main()
    {int i,j;
    char a[4][72];
    for(i=0;i<4;i++)
    gets(a[i]);
    int b[26];
    memset(b,0,sizeof(b));
    for(i=0;i<4;i++)
    for(j=0;j<strlen(a[i]);j++)
    switch(a[i][j])
    {case'A':b[0]++;break;
    case'B':b[1]++;break;
    case'C':b[2]++;break;
    case'D':b[3]++;break;
    case'E':b[4]++;break;
    case'F':b[5]++;break;
    case'G':b[6]++;break;
    case'H':b[7]++;break;
    case'I':b[8]++;break;
    case'J':b[9]++;break;
    case'K':b[10]++;break;
    case'L':b[11]++;break;
    case'M':b[12]++;break;
    case'N':b[13]++;break;
    case'O':b[14]++;break;
    case'P':b[15]++;break;
    case'Q':b[16]++;break;
    case'R':b[17]++;break;
    case'S':b[18]++;break;
    case'T':b[19]++;break;
    case'U':b[20]++;break;
    case'V':b[21]++;break;
    case'W':b[22]++;break;
    case'X':b[23]++;break;
    case'Y':b[24]++;break;
    case 'Z':b[25]++;break;
    default:break;}
    int m=0;
    for(i=0;i<26;i++)
    if(m<b[i])m=b[i];
    
    
    for(i=m;i>0;i--)
    {for(j=0;j<25;j++)
    
    
    {if(b[j]>=i)
    cout<<'*'<<" ";
    else
    cout<<"  ";
    }
    if(b[25]>=i)
    cout<<'*';
    else
    cout<<" ";
    
    cout<<endl;
    }
    for(i=65;i<90;i++)
    cout<<char(i)<<" ";
    cout<<'Z'<<endl;
    
    return 0;
    
    }
     
  • 相关阅读:
    HDU 6370 dfs+并查集
    牛客网暑期ACM多校训练营(第六场)G
    HDU 6351暴力枚举 6354计算几何
    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D
    2018 百度之星 初赛 第六题 HDU6349
    HDU 6336 子矩阵求和
    HDU 6333 莫队+组合数
    BZOJ 2308 莫队入门经典
    Linux系统管理第一章
    2019年7月17日
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387849.html
Copyright © 2011-2022 走看看