A Contesting Decision C语言 ZOJ1764
Judging a programming contest is hard work, with demanding contestants, tedious decisions, and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.
Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.
Scoring
There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems, then the winner is the team with the fewest penalty points.
Input
For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.
Line 1 <nTeams>
Line 2-n+1 <Name> <p1Sub> <p1Time> <p2Sub> <p2Time> ... <p4Time>
The first element on the line is the team name, which contains no whitespace. Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.
<b< dd="">
Output
The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.
<b< dd="">
Sample Input
4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80
Sample Output
Penguins 3 475
这道题我是输入一对的数据就处理一队的数据。先设冠军队解题数为0,解题用时为0,每输入一队,就计算该队解题数和用时,然后和冠军队比较,如果解题数比冠军队多或解题数相同,但是用时比冠军队短,就将冠军队的所有数据更换为该队的数据。在所有的输入完成后输出冠军队的数据。
在计算当前的队伍的解题用的时间时,我是每次读入一道题的数据,读四次,我觉得这样比较方便。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 6 int main(void){ 7 int n,i,j; 8 char winner[50],name[50];//winner是冠军队的名字,name是输入的队伍的名字 9 int winsum,wints,nsum,nts; 10 int a,b; 11 while(scanf("%d",&n)==1){//读入队伍数量 12 wints=winsum=0;//初始化冠军队的题数,时间 13 for(i=0;i<n;i++){//从第一支队伍开始循环 14 nts=nsum=0;//初始化当前队的题数,时间 15 scanf("%s",name);//读入队伍名 16 for(j=0;j<4;j++){//分别判断每组数据 17 scanf("%d %d",&a,&b); 18 if(b!=0){//题解出来了 19 nsum=nsum+b+((a-1)*20); 20 nts++; 21 } 22 } 23 if(nts>wints){ 24 wints=nts; 25 winsum=nsum; 26 strcpy(winner,name); 27 } 28 else if(nts==wints){ 29 if(nsum<winsum){ 30 winsum=nsum; 31 strcpy(winner,name); 32 } 33 } 34 } 35 printf("%s %d %d\n",winner,wints,winsum);//输出 36 } 37 return 0; 38 }