• J


    J - Vertical Histogram(1.5.7)
    Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

    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 <cstdio>
    #include <ctype.h>
    #include<string>
    using namespace std;
    int main()
    {
    	int cnt[30],max=-1;
    	int i,j;
    	memset(cnt,0,sizeof(cnt));
    	for(i=0;i<4;i++)
    	{
    		string s;
    		getline(cin,s);
    		for(j=0;j!=s.size();j++)
    			if(isupper(s[j])) //判断是否为大写字母
    				cnt[s[j]-'A']++;
    	}
    	for(i=0;i<26;i++)
    		if(cnt[i]>max) 
    			max=cnt[i];//max记录的是出现最多的字母的个数
    		for(i=max;i>0;i--)
    		{
    			for(j=0;j<26;j++)
    				if(cnt[j]>=i) 
    					printf("* ");
    				else printf("  ");
    				puts("");
    		}
    		for(i=0;i<26;i++)
    			printf("%c ",'A'+i);
    		puts("");
    		return 0;
    }

     
  • 相关阅读:
    HDU 1556 差分,前缀和
    Full permutation
    PAT B1029
    字串简介
    阵列(3)
    完形填空
    关于c的比较
    19 阵列的复制
    switch述句
    阵列变数(2)
  • 原文地址:https://www.cnblogs.com/u013533289/p/4477313.html
Copyright © 2020-2023  润新知