#C13625. Percentage Frequencies Calculation
Percentage Frequencies Calculation
Percentage Frequencies Calculation
You are given a list of words along with their frequencies. Your task is to compute the percentage frequency for each word relative to the total count of all words.
Let the frequency of a word be f and the total frequency be T. The percentage frequency is computed as:
\(\frac{f}{T} \times 100\)
The result should be rounded to one decimal place. Print each word and its computed percentage on a separate line, separated by a single space.
Example:
Input: 4 apple 4 banana 2 orange 1 grape 3</p>Output: apple 40.0 banana 20.0 orange 10.0 grape 30.0
Good luck!
inputFormat
The first line contains an integer n
(1 ≤ n ≤ 105), the number of words. Each of the following n
lines contains a word (a non-empty string without spaces) and an integer frequency (1 ≤ frequency ≤ 109), separated by a space.
outputFormat
Output n
lines, each line containing the word and its percentage frequency (rounded to one decimal place) separated by a single space. The order of output should be the same as the input order.
4
apple 4
banana 2
orange 1
grape 3
apple 40.0
banana 20.0
orange 10.0
grape 30.0
</p>