04: vertical histogram, 04 vertical Histogram

Source: Internet
Author: User

04: vertical histogram, 04 vertical Histogram
4: vertical Histogram

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Enter four lines of text consisting of uppercase letters, and output a vertical histogram showing the number of occurrences of each character. Note: Only the number of occurrences of the output character is used, and the number of outputs of white space characters, numbers, or punctuation characters is not used.

Input
The input contains four lines of text consisting of uppercase letters. The number of characters on each line cannot exceed 80.
Output
The output contains several rows. The last row contains 26 uppercase letters separated by a space. The preceding lines contain spaces and star numbers. Each letter appears several times and an asterisk is output above the letter. Note: The first line of the output cannot be a blank line.
Sample Input
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.THIS IS AN EXAMPLE TO TEST FOR YOURHISTOGRAM 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
Translated from USACO 2003 February Orange.
 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 char a[10001]; 7 char b[10001]; 8 char c[10001]; 9 char d[10001];10 int ans[10001];11 int tot;12 char kong[4];13 int month[14]={31,28,31,30,31,30,31,31,30,31,30,31};14 int maxn=-1;15 int main()16 {17     gets(a);int la=strlen(a);18     gets(b);int lb=strlen(b);19     gets(c);int lc=strlen(c);20     gets(d);int ld=strlen(d);21     for(int i=0;i<la;i++)22         ans[(int)a[i]]++;23     for(int i=0;i<lb;i++)24         ans[(int)b[i]]++;25     for(int i=0;i<lc;i++)26         ans[(int)c[i]]++;27     for(int i=0;i<ld;i++)28         ans[(int)d[i]]++;29     for(int i=65;i<=90;i++)30     {31         if(ans[i]>maxn)maxn=ans[i];32     }33     for(int i=maxn;i>=1;i--)34     {35         for(int j=65;j<=90;j++)36         {37             if(ans[j]<i)cout<<' '<<" ";38             else cout<<'*'<<" ";39         }40         cout<<endl;41     }42     for(int i=65;i<=90;i++)43     {44         cout<<(char)i<<" ";45     }46     return 0;47 }

The key to this question is how to obtain the most frequently used letters and how to output them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.