URAL 1263. Elections

1. 题目

http://acm.timus.ru/problem.aspx?space=1&num=1643

1263. Elections

Time limit: 1.0 second
Memory limit: 64 MB
The next in turn elections are to come soon. All the fences are postered with leaflets and the mail boxes are full of throwaways. Cheeky guys are looking at us from TV’s and promise to make our life better… And programmer Vasechkin is knee-deep in work. He is to write a program that would calculate the results of voting.

Input

The first line contains a number of candidates N (1 ≤ N ≤ 10000) and a number of electors M (1 ≤ M ≤ 10000). Then M lines follow, each one contains a number of candidate that the elector voted for. The candidates are numbered with integers from 1 to N.

Output

Output N lines. The i-th line should contain the percent of electors that voted for the i-th candidate (to within 2 decimals).

Sample

input output
3 6
1
2
3
2
1
1
50.00%
33.33%
16.67%
Problem Author: Den Raskovalov
Problem Source: Open collegiate programming contest for high school children of the Sverdlovsk region, October 11, 2003

2. 思路

测试用算术题。

3.代码

#include <stdio.h>

#define MAX_N 10001
#define MAX_M 10001

void solveE1A();

int main() {
    solveE1A();
    return 0;
}

int votes[MAX_M] = {0};
void solveE1A() {
    int candNum, electorNum, cand, i;
    float percent;
    
    scanf("%d %d", &candNum, &electorNum);
    
    for (i = 1; i <= electorNum; ++i) {
        scanf("%d", &cand);
        ++votes[cand];
    }
    
    for (i = 1; i <= candNum; ++i) {
        percent = 100.0 * votes[i] / electorNum;
        printf("%2.2f%%\n", percent);
    }
}