NUC1154 Vertical Histogram【打印图案】
2017-06-27 05:35
405 查看
Vertical Histogram
时间限制: 1000ms 内存限制: 10000KB
通过次数: 1总提交次数:
1
问题描述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.
输入描述
* Lines 1..4: Four lines of upper case text, no more than 72 characters per line.
输出描述
* 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.
样例输入
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. THIS IS AN EXAMPLE TO TEST FOR YOUR HISTOGRAM PROGRAM. HELLO!
样例输出
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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
来源
USACO 2003 February Orange
问题分析:(略)
这个问题和《POJ2136 Vertical Histogram【打印图案】》是同一个问题,代码直接用就AC了。
程序说明:参见参考链接。
参考链接:POJ2136 Vertical Histogram【打印图案】
题记:程序做多了,不定哪天遇见似曾相识的。
AC的C++程序如下:
/* POJ2136 HDU2708 Vertical Histogram */ #include <iostream> #include <string> #include <cstring> #include <cctype> using namespace std; const int MAXN = 26; int acount[MAXN]; int main() { int linecount, max; string s; memset(acount, 0, sizeof(acount)); linecount = 0; while (getline(cin, s)) { // 统计字母 for(int i=0; i<(int)s.size(); i++) if(isalpha(s[i])) acount[s[i] - 'A']++; // 每4行输出一次结果 if(++linecount == 4) { linecount = 0; // 计算最大的统计值 max = 0; for(int i=0; i<MAXN; i++) if(acount[i] > max) max = acount[i]; // 输出max行 for(int i=max; i>0; i--) { for(int j=0; j<MAXN; j++) { if(acount[j] >= i) cout << "* "; else cout << " "; } cout << endl; } for(int i=0; i<MAXN; i++) cout << (char)('A' + i) << " "; cout << endl; } } return 0; }
相关文章推荐
- NUC1014 排版题.输出排列成菱形的字母【打印图案】
- 用c语言在屏幕上打印图案
- POJ2136 Vertical Histogram【打印图案】
- 打印出菱形图案
- 图案打印
- 3.图案打印
- 利用java打印出金字塔图案
- 黑马程序员——折纸问题、九九乘法表和菱形图案的打印
- 在屏幕上打印出n行的金字塔图案,如,若n=5,则图案如下:
- Java循环练习:打印图案-4
- LingXing.java 题目:打印出如下图案(菱形) * *** ***** ******* ***** *** *
- 打印下面由*号组成的图案
- 打印数字菱形图案
- HDU3257 Hello World!【打印图案+位运算】
- 图案打印: 记法与解释器
- 输入N,打印对应N行的图案。
- /*题目:打印出如下图案(菱形)
- sdut——图案打印
- Java循环练习:打印图案-5
- 【程序19】 题目:打印出如下图案(菱形) * *** ****** ******** ****** *** *