Ballot Analyzing Device

题目连接:

http://codeforces.com/gym/100269/attachments

Description

Election committee of Flatland is preparing for presidential elections. To minimize human factor in ballot

counting they decided to develop an automated Ballot Analyzing Device (BAD).

There are n candidates running for president. The ballot contains one square field for each candidate.

The voter must mark exactly one of the fields. If no field is marked or there are two or more marked

fields, the ballot is invalid. Each voter puts his/her ballot to a special scanner in BAD. The scanner

analyzes marks on the ballot and creates a special voting string of n characters: ‘X’ for marked field and

‘.’ for unmarked one. Now voting strings must be analyzed to get the report. Your task is to develop a

report generator for BAD.

Given voting strings for all ballots, your program must print the voting report. Candidates in the report

must be arranged in order of decreasing number of votes. If two candidates have the same number of

votes, they must have the same order as in a voting ballot. For each candidate calculate his/her result

in percent (if the candidate received p votes, the result in percent is 100p/m). The last line of the report

must indicate the percentage of the invalid ballots.

Input

The first line contains two integers n and m — the number of candidates and the number of ballots

(2 ≤ n ≤ 10; 1 ≤ m ≤ 1000). The following n lines contain last names of candidates. Each name is a

string of at most 100 English letters. There is no candidate named “Invalid”.

Then m lines follow, each of them contains one voting string.

Output

Print n+ 1 lines. First print results for candidates in percent. For each candidate print his/her last name

followed by a space and then his/her result in percent and a percent sign ‘%’. The last line must specify

the percentage of invalid ballots: a word “Invalid” followed by a space, the percentage of invalid ballots

and a percent sign.

Round all numbers to exactly two digits after the decimal point. If the number is exactly in the middle

of two representable numbers, output the greater one (e.g. output “12.35” for 12.345).

Sample Input

4 7

Loudy

Apples

Dogman

Miller

.X..

X...

....

..X.

..XX

..X.

..X.

Sample Output

Dogman 42.86%

Loudy 14.29%

Apples 14.29%

Miller 0.00%

Invalid 28.57%

Hint

题意

有m个人给n个人投票,每个人最多给一个人投票,如果投了两个人或者没有投票的话,那么这张票就算无效

然后让你按照票数高低排序,如果票数相同,就按照一开始的顺序输出

题解:

模拟题,当然也是水题

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1050;
char s[maxn];
pair<int,pair<int,string> > p[maxn];
int main()
{
freopen("bad.in","r",stdin);
freopen("bad.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
int t=0;
for(int i=0;i<n;i++)
cin>>p[i].second.second,p[i].second.first=n-i;
for(int i=0;i<m;i++)
{
scanf("%s",s);
int flag = 0,cnt = 0;
for(int j=0;j<n;j++)
{
if(s[j]=='X')
flag=j,cnt++;
}
if(cnt==0||cnt>1)
t++;
else
p[flag].first++;
}
sort(p,p+n);
for(int i=n-1;i>=0;i--)
{
cout<<p[i].second.second<<" ";
printf("%.2f%%\n",100.0*p[i].first/m);
}
printf("Invalid %.2f%%\n",100.0*t/m);
}

最新文章

  1. Android编码规范03
  2. MySQL 使用XtraBackup的shell脚本介绍
  3. flexBox布局 -- 兼容性
  4. 黑马程序员——C语言基础 枚举 宏定义 自定义 static exterm
  5. HttpClient封装工具类
  6. 如何安装最新的 XFCE 桌面?
  7. 转:Docker学习---挂载本地目录
  8. 如何应对Session丢失》》State Server
  9. java--接口和抽象类
  10. PAT1013. Battle Over Cities(邻接矩阵、邻接表分别dfs)
  11. 如何判断list中是否包含某个元素
  12. 30种mysql优化sql语句查询的方法
  13. JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)
  14. 安装mysqlsla性能分析工具
  15. 【排序算法】快速排序算法 Java实现
  16. [Leetcode] Binary search--275 H-Index
  17. Java 字符编码 ASCII、Unicode、UTF-8、代码点和代码单元
  18. Codeforces Round #418 (Div. 2) B. An express train to reveries
  19. Microsoft Bot Framework 上手
  20. jQuery 动画效果 与 动画队列

热门文章

  1. docker使用小记
  2. bisai2.py
  3. C基础 内存越界和内存监测的简单处理
  4. 外部div不能包裹内部div的问题
  5. 【mongo】用户添加、导入数据库、连接VUE
  6. LeetCode解题报告—— Longest Valid Parentheses
  7. 《java并发编程实战》读书笔记12--原子变量,非阻塞算法,CAS
  8. request.getRemoteAddr() 获取的值为0:0:0:0:0:0:0:1的原因及解决办法
  9. redis之(五)redis的散列类型的命令
  10. Linux下cp命令的使用说明