zoukankan      html  css  js  c++  java
  • 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;
    }

     
  • 相关阅读:
    每天问自己十个问题
    FreeBSD入门安装及汉化
    商人的10条赚钱规则
    端口扫描程序nmap使用手册
    canvas
    表单2.0
    H5数据保存之storage
    Linux基础命令2
    Linux文件权限与修改
    Linux基础命令1
  • 原文地址:https://www.cnblogs.com/u013533289/p/4477314.html
Copyright © 2011-2022 走看看