Vertical Histogram

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 15400 Accepted: 7462

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"stdio.h"
int main()
{
	int i, max = 0, count[26] = {0};
	char input[72];
	for (i = 0; i < 4; i++) {
		char input[72] = {' '};
		gets(input);
		for (int j = 0; j < 72; j++) {
			int map = input[j] - 65;
			if (map >= 0 && map <= 25) {
				count[map]++;
				if (count[map] > max) {
					max = count[map];
				}
			}
		}
	}
	for (i = max; i > 0; i--) {
		for (int j = 0; j < 26; j++) {
			if (count[j] >= i) {
				count[j]--;
				if (j == 25) {
					printf("*");
				} else {
					printf("* ");
				}
			} else {
				if (j == 25) {
					printf(" ");
				} else {
					printf("  ");
				}
			}
		}
		printf("\n");
	}
	for (i = 0; i < 26; i++) {
		if (i == 25) {
			printf("%c", (char)(i + 65));
		} else {
			printf("%c ", (char)(i + 65));
		}
	}
	printf("\n");
	return 0;
}
Result Memory Time Language Code Length
Accepted 160K 0MS C++ 825B

 

Tonitech版权所有 | 转载请注明出处: http://www.tonitech.com/1767.html

发表评论