Converting Counts to Percentages Before Charting
Harbourview Consulting publishes the same survey every quarter, and the number of people answering it changes a lot from one quarter to the next. Charting raw counts makes a busy quarter look like a shift in opinion, so the chart shows each category's share of that quarter's total instead, as a percentage. The row of figures printed under the chart is what is checked here: one percentage per category, in the order the categories appear in the file.
Task: Print each category's percentage share of the total.
Input
The first line holds an integer n, the number of categories. Each of the next n lines holds a category name and its count, separated by a single space. A name contains no spaces.
Output
One line holding n percentages separated by single spaces, in the order the categories were read, each written with exactly one decimal place. A category holding a third of the responses prints as 33.3.
Example:
Input:
2
A 30
B 70
Output:
30.0 70.0
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in