程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 2136 Vertical Histogram

POJ 2136 Vertical Histogram

編輯:C++入門知識

POJ 2136 Vertical Histogram


分析:很久以前,在《K&R》上面碰到過這個題,只不過比這個復雜一點。。。。

也是水題,沒什麼說的,注意一下細節,比如輸出的格式等,還有就是,一開始用的for循環,每輸入一行結束後就直接打印,好郁悶^~_~^

 

 

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 
#include 
#include 
#include 

using namespace std;

int main()
{

	int len,i,j,maxhigh=0;
	string s;
	int c[26];
	memset(c,0,sizeof(c));

	while (cin>>s)
	{
		len=s.length();
		for(i=0;i=65 && s[i]<=90)
				++c[s[i]-'A'];
	}


	for(i=0;i<26;i++)
		if(maxhigh0;i--)
	{
		for(j=0;j<26;j++)
			if(c[j]>=i)
				printf("* ");
			else
				printf("  ");
		printf("\n");
	}

	for(i=0;i<26;i++)
	{
		if(i>0)
			printf(" ");
		printf("%c",i+'A');
	}

	printf("\n");
	return 0;
}


 

 

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved