zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1598 垂直柱状图

    题目描述
    写一个程序从输入文件中去读取四行大写字母(全都是大写的,每行不超过100个字符),然后用柱状图输出每个字符在输入文件中出现的次数。严格地按照输出样例来安排你的输出格式。

    输入格式
    四行字符,由大写字母组成,每行不超过100个字符

    输出格式
    由若干行组成,前几行由空格和星号组成,最后一行则是由空格和字母组成的。在任何一行末尾不要打印不需要的多余空格。不要打印任何空行。

    输入输出样例
    输入 #1 复制

    THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
    THIS IS AN EXAMPLE TO TEST FOR YOUR
    HISTOGRAM PROGRAM.
    HELLO!
    

    输出 #1

    
                                *
                                *
            *                   *
            *                   *     *   *
            *                   *     *   *
    *       *     *             *     *   *
    *       *     * *     * *   *     * * *
    *       *   * * *     * *   * *   * * * *
    *     * * * * * *     * * * * *   * * * *     * *
    * * * * * * * * * * * * * * * * * * * * * * * * * *
    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
    

    说明/提示
    每行输出后面不允许出现多余的空格。

    import java.util.Scanner;
     
    public class Main {
    	private static Scanner cin;
     
    	public static void main(String args[]) throws Exception {
    		cin = new Scanner(System.in);
    		int maxChar = 0;
    		int[] count = new int[26]; 
    		String line = null;
    		char[] character = null;
    		for(int i=0;i<4;i++) {
    			line = cin.nextLine();
    			character = line.toCharArray();
    			for(char c : character) {
    				if(32 == c) {
    					//space
    					continue;
    				}else if(c>=65 & c<= 90) {
    					count[c-65] += 1;
    					if(count[c-65]>maxChar) {
    						maxChar = count[c-65];
    					}
    				}
    			}
    		}
     
    		char[][] outChar = new char[26][maxChar];
    		for(int i = 0;i<26;i++) {
    			for(int j = 0; j<maxChar;j++) {
    				if(j<count[i]) {
    					outChar[i][j]='*';
    				}else {
    					outChar[i][j] = ' ';
    				}
    			}
    		}
    		
    		for(int j=maxChar-1;j>=0;j--) {
    			for(int i=0;i<26;i++) {
    				if(i<25) {
    					System.out.print(outChar[i][j]+" ");
    				}else {
    					System.out.print(outChar[i][j]);
    				}
    			}
    			System.out.println();
    		}
    		for(int i=0;i<26;i++) {
    			if(i<25) {
    				System.out.print((char)(65+i)+" ");
    			}else {
    				System.out.print((char)(65+i));
    			}
    		}
    		System.out.println();
    	}
    	
    	
    }
     
    
  • 相关阅读:
    ExtJs系列教程
    linux 服务器时间 timedatectl命令时间时区操作详解
    aws CloudWatch Events
    AWS Shield
    aws ssm指令
    failed to set bridge addr: "cni0" already has an IP address different from 10.244.0.1/24
    AWS Systems Manager
    Amazon Inspector
    AWS 安全培训
    Amazon Inspector
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076228.html
Copyright © 2011-2022 走看看