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

     
  • 相关阅读:
    IoT(Internet of things)物联网入门介绍
    SIP协议解析
    nginx内核优化参考
    下线注册中心微服务
    vscode配置vue+eslint自动保存去除分号,方法与括号间加空格,使用单引号
    linux常见故障整理
    部署Glusterfs
    解决 eslint 与 webstrom 关于 script 标签的缩进问题
    单个maven项目使用阿里云镜像方法
    idea启动tomcat日志乱码解决办法
  • 原文地址:https://www.cnblogs.com/u013533289/p/4477313.html
Copyright © 2020-2023  润新知