GrapeCity written test question
Title Source
Title Description
Title: Data Visualization
Programming language: not limited
Title Description: There is a saying that goes like this: “A text is better than a table, and a table is better than a chart”. The image describes the very different efficiency and experience that charts bring to the receiver when conveying information. Therefore, at a time when computer computing power, data size and decision-making needs are increasing, the use of data visualization is becoming more and more common.
The scope of data visualization is wide and involves many concepts and areas such as data acquisition, processing, modeling, graphics, human-computer interaction, etc. To get started faster and have a better experience, it is wiser to use professional tools and services like DragonFly BI.
Today, we take a hands-on approach to simple data visualization with a simplified proposition. Write a program that, for a given set of data and requirements, outputs a bar graph composed of characters.
Input
- In the first row, an integer N (1<=n<=20), indicating the number of entries in this data set.
- The second line, two strings, is used to indicate how the data is sorted on the bar chart. The first string is “Name” or “Value”, which indicates that the sorting is based on the name or value of the data item; the second string is “ASC” or “DESC”, indicating ascending or descending order.
- The subsequent N lines, each containing a string S and a number V separated by spaces, represent a piece of data. s, the name of the data entry, contains only lowercase letters, and V, the corresponding value, is an integer, (0<=V<=1,000,000)
Output
Chart outer frame corner symbols:
- “┌”(\u250c)
- “┐”(\u2510)
- “└”(\u2514)
- “┘”(\u2518)
Horizontal and vertical lines in the chart:
- “─”(\u2500)
- “│”(\u2502)
Various cross lines in the chart:
- “├”(\u251c)
- “┤”(\u2524)
- “┬”(\u252c)
- “┴”(\u2534)
- “┼”(\u253c)
Characters used to spell columns:
- “█”(\u2588)
Spaces in the chart:
- “ ”(\u0020)
The width of the name area in the chart is determined by the maximum length of the names in the set of data, all names are aligned to the right, the maximum length of the columns in the chart is 20, the length of each column is obtained by multiplying the ratio of the data corresponding to the column and the maximum value in the set of data (this value must be greater than 0) with 20, and rounding off the part that is less than one cell.
Input Example
|
|
Output Example
Problem Solving
|
|