POJ 2136 Vertical Histogram print special graphics
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
#include
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;}