• 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;
    }

     
  • 相关阅读:
    翻转单词顺序
    java layout 表格项增加、删除、修改
    Hadoop学习之HBase
    protected的一些功能
    hdu4431 Mahjong
    kendo ui gird温馨提示(使用本地数据) 一个
    TOP计划猿10最佳实践文章
    Java高级应用(一个)-文件夹监控服务
    BSD介绍
    获取编译学习笔记 (十三)—— 外部中断
  • 原文地址:https://www.cnblogs.com/u013533289/p/4477314.html
Copyright © 2020-2023  润新知