POJ 2136 Vertical Histogram prints special graphics, pojhistogram
Print the output format as required.
These are some interesting questions. The question itself is not difficult. The difficulty is to test how to program elegantly. It is mainly to test the basic programming skills.
In addition, it seems that the test system is not very strict and does not judge the redundant spaces behind it. According to the requirements of the question, we need to strictly remove the redundant spaces behind it.
To solve this problem, you need more code.
The following shows that I use an extra array spaceHeight [ALP_LEN [to solve this problem, so that there is no half of the extra space characters.
#include <cstdio>#include <string.h>const int MAX_N = 75;const int ALP_LEN = 26;const int LINE_N = 4;short height[ALP_LEN];short spaceHeight[ALP_LEN];char chs[MAX_N];inline int max(int a, int b) { return a > b ? a : b; }inline void getAlphaCount(char str[]){int i = 0;while (str[i]){if ('A' <= str[i] && str[i] <= 'Z') height[str[i]-'A']++;i++;}}int main(){while (gets(chs)){memset(height, 0, sizeof(height));getAlphaCount(chs);for (int i = 0; i < LINE_N-1; i++){gets(chs);getAlphaCount(chs);}spaceHeight[ALP_LEN-1] = height[ALP_LEN-1];for (int i = ALP_LEN-2; i >= 0; i--){spaceHeight[i] = max(spaceHeight[i+1], height[i]);}for (int h = spaceHeight[0]; h > 0; h--){for (int j = 0; j < ALP_LEN; j++){if (spaceHeight[j] < h) break;if (j > 0) putchar(' ');if (height[j] < h) putchar(' ');else putchar('*');}putchar('\n');}for (int i = 0; i < ALP_LEN; i++){if (i > 0) putchar(' ');putchar(char(i+'A'));}putchar('\n');}return 0;}
ACM solution report
Category of a poj question
Mainstream algorithms:
1. Search // trace back
2. DP (Dynamic Planning)
3. Greedy
4. Graph Theory // Dijkstra, Minimum Spanning Tree, and network stream
5. Number Theory // solves the modulus linear equation
6. Calculate the area and perimeter of the joint of the geometric/Convex Shell with the same placement of the rectangle
7. Composite math // Polya Theorem
8. Simulation
9. Data Structure // check the collection and heap
10. Game Theory
1. Sorting
1423,169 4, 1723,172 7, 1763,178 8, 1828,183 8, 1840,220 1, 2376,
2377,238 0, 1318,187 1971,197, 1990,200 4, 2002,209 1, 2379 2,
1002 (character processing is required, and sorting can be done in a fast way) 1007 (stable sorting) 2159 (difficult to understand)
2231 2371 (simple sorting) 2388 (sequence statistics algorithm) 2418 (Binary sorting tree)
2. Search, backtracking, and traversal
2329
Simple: 1128,116 6, 1176,123 1, 1256,127 0, 1321,154 3, 1606,166 4,
1731,174 2, 1745,184, 1950,203, 2157,218 8, 2183,238 2, 2386,242 1, 6
Not easy: 1024,105 4, 1117,116 7, 1708,174 6, 1775,187 8, 1903,196 6, 2046,
2197,234 9
Recommended: 1011,119 0, 1191,141 6, 1579,163 2, 1639,165 9, 1680,168 3, 1691,
1709,171 4, 1753,1771, 1826,185 5, 1856,189 0, 1924,193 5, 1948,197 9, 1980,217 2331,233 1979, 1980 9, (similar to the maze), (higher requirements for pruning)
3. Calendar
1008 2080 (Be careful with such questions)
4. Enumeration
1387,141, 2245,232, 2363,238 1, 1650 6, (higher pruning requirements), (decimal precision problem)
5. Typical data structure Algorithms
Easy: 1182,165 6, 2021,202 3, 2051,215 3, 2227,223 6, 2247,235 2,
2395
Not easy: 1145,117 7, 1195,122 7, 1661,183 4
Recommended: 1330,133 8, 1451,147 0, 1634,168 9, 1693,170 3, 1724,198 8, 2004,
2010,211 9, 2274
1125 (fresh algorithm), 2421 (Minimum Spanning Tree of the graph)
6. Dynamic Planning
1037 A decorative fence,
1050 To the Max,
1088 skiing,
1125 Stockbroker Grapevine,
1141 Brackets Sequence,
1159 Palindrom ...... remaining full text>
Translate http: // pojorg/problem? Id = 2136 translate the description.
Please write a program to read four lines of fully capitalized text input from the input file (each line cannot exceed 72 characters) and print the vertical bar chart, displays the number of times each letter (not including spaces, numbers, and punctuation) appears in the full-capital input. The output format is shown below. Enter * Rows 1 to 4: four rows of all uppercase text. Each line cannot exceed 72 characters and output * Rows 1 ?? : A number of planet signs and spaces, followed by a line of uppercase letters, separated by spaces. Do not print unnecessary spaces behind each line. Do not print blank lines before. Input example the quick brown fox jumped over the lazy dog. this is an example to test for your histogram program. HELLO! Output example ************************************** **************************************** * ****** 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