Gym 100269B-Ballot Analyzing Device
2016-06-03 14:42
267 查看
Input file: bad.in
Output file: bad.out
Time limit: 2 seconds
Memory limit: 256 megabytes
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).
Example
题意:求每个人的选票比例排序后输出。
代码:
4000
Output file: bad.out
Time limit: 2 seconds
Memory limit: 256 megabytes
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).
Example
题意:求每个人的选票比例排序后输出。
代码:
#include <cstdio> #include <algorithm> #include <cstring> #include <iostream> #include <map> #include <queue> #include <utility> using namespace std; const int maxn=1050; char s[maxn]; pair<int,pair<int,string> >p[maxn]; int main (void) { // freopen("bad.in","r",stdin); // freopen("bad.out","w",stdout); int n,m; cin>>n>>m; int a=0; for(int i=0;i<n;i++) { cin>>p[i].second.second; //p[i].second.first=n-i; p[i].second.first=i; } for(int i=0;i<m;i++) { scanf("%s",s); int flag,ans; flag=0;ans=0; for(int j=0;j<n;j++) { if(s[j]=='X') { flag=j; ans++; } } if(ans!=1) a++; else p[flag].first++; } sort(p,p+n); for(int i=n-1;i>=0;i--) { //printf("%s ",p[i].second.second); cout<<p[i].second.second<<" "; printf("%.2f%%\n",100.0*p[i].first/m); } printf("Invalid %.2f%%\n",100.0*a/m); return 0; }
4000
相关文章推荐
- 第一次使用Android Studio时你应该知道的一切配置
- 21天速成 C++?编程生涯的一点思考
- 致第一次安装RIME的你
- 【转载】 ionic 的 下拉刷新 与 上拉加载
- poj 3187 next_permutation简单应用
- (转载)Qt 的线程与事件循环——可打印threadid进行观察槽函数到底是在哪个线程里执行,学习moveToThread的使用)
- sdl在一些电脑上无法播放出声音
- 打通流程管理与MIS数据的管道是运用工作流程工具搭建业务系统的关键
- STM32 OSC_IN跟OSC_OUT的作用 和 各种接法
- 【iOS开发】HTTP请求错误码 ? CodeType
- Same Tree
- ElasticSearch实战-入门
- fork之后子进程到底复制了父进程什么
- 严苛模式(StrictMode)
- HDFS源码分析EditLog之读取操作符
- HDFS源码分析EditLog之获取编辑日志输入流
- SSL证书种类分析
- 视图切换相关
- Xcode 导出APP中日志
- 创建容器Error response from daemon: dial tcp 72.52.4.91:8080: connection refused