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

     
  • 相关阅读:
    Android ADB批处理脚本
    【转载】SecureCRT配色推荐和永久设置
    【转载】Ubuntu中Source Insight的使用
    Ubuntu美化操作
    【转】数据线上的串联小电阻(图)
    VMware下利用ubuntu13.04建立嵌入式开发环境之三
    VMware下利用ubuntu13.04建立嵌入式开发环境之二
    VMware下利用ubuntu13.04建立嵌入式开发环境之一
    ubuntu 13.04 telnet 详细配置
    candence 知识积累4
  • 原文地址:https://www.cnblogs.com/u013533289/p/4477313.html
Copyright © 2011-2022 走看看