POJ 2136 Vertical Histogram print special graphics

Source: Internet
Author: User

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;}
  
 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.