1198: Exam Ranking (2) (Structure Topics)

1198: Exam Ranking (2) (Structure Topics)

Title description
ACM International Collegiate Programming Contest, English full name: ACM International Collegiate Programming Contest (ACM-ICPC or ICPC) is sponsored by the American Computer Society (ACM) An annual competition for programming, analysis, and problem-solving skills. After more than 30 years of development, the ACM International College Student Programming Contest has developed into the most influential college student computer competition. It is generally referred to as the ACM competition (although logically it should be referred to as the ICPC).
The scoring rules of the ACM competition are as follows:
First, the ranking is based on the number of questions passed. Teams with the same number of questions are ranked according to the penalty time (the team with the smaller penalty time is ranked first). Teams with smaller team ids are listed first on the ranking table).
For the calculation of penalty time. The team's overall penalty time is equal to the sum of the team's penalty time for each question. For the penalty time of a question, if the question is not passed at the end (not submitted correctly), the penalty time for this question is 0, otherwise the penalty time for this question is: from the beginning of the competition to the first correct submission of the question time + number of bad commits before first pass * 20 minutes.
For example: a test has 8 questions (A, B, C, D, E, F, G, H), each question has a quantity mark under the corresponding question number, and a negative number indicates that the student is in the question The number of wrong submissions that have been in the past, but there is no AC yet. The positive number represents the time spent on AC. If the positive number a is followed by a pair of parentheses, and there is an integer b in it, it means that the student has submitted the question AC. , it took time a, and at the same time, it has submitted b times by mistake, so for the following input data:
its ranking from high to low should be like this:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0 The first line of
input
data is the number of exam questions n (1≤n≤12), each line of data describes a student's username (a string of no more than 10 characters) and the number of questions for all n questions. The status of the answer, its description is in the format of the quantity mark in the problem description, see the table above, the number of submissions is always less than 100, and the time spent on AC is always less than 1000. No more than 100 people take the test.
Output
The test status of these students is output as a real-time ranking. The real-time ranking is obviously first ranked according to the number of AC questions, more first, and then according to the number of time points, less first, if it happens that the first two are equal, then according to the lexicographic order of the name, the smallest first. . Each student occupies one line, and outputs the name (10 characters wide, left-aligned), the number of questions made (2 characters wide, right-aligned) and time points (4 characters wide, right-aligned). There is a space between the name, number of questions and time minutes.
Sample input Copy
8
Smith -1 -16 8 0 0 120 39 0
John 116 -2 11 0 0 82 55(1) 0
Josephus 72(3) 126 10 -3 0 47 21(2) -2
Bush 0 -1 -8 0 0 0 0 0
Alice -2 67(2) 13 -1 0 133 79(1) -1
Bob 0 0 57(5) 0 0 168 -7 0
Sample output Copy
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
Source/Classification

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct team{
    
    
    char name[11];
    int r;//做对的题数
    int t;//总的消耗时间
}team;

int cmp(team a,team b){
    
    
    if(a.r<b.r) return 1;
    if(a.r==b.r&&a.t>b.t) return 1;
    if(a.r==b.r&&a.t==b.t&&strcmp(a.name,b.name)>0) return 1;
    return 0;
}

int main(){
    
    
    int n,i=0,x,y;
    char ch;
    team a[100],t;
    scanf("%d",&n);

    while(scanf("%s",a[i].name)!=EOF){
    
    
        a[i].r=0;a[i].t=0;//初始化
        for(int j=0;j<n;j++){
    
    
            scanf("%d",&x);
            if(x>0){
    
    
                a[i].r++;//正确的题+1
                a[i].t+=x;//加上时间
            }
            ch=getchar();
            if(ch=='('){
    
    
                scanf("%d",&y);
                a[i].t+=20*y;//加上因为提交错误的时间
                getchar();
            }
        }
        i++;
    }

    for(int j=0;j<i-1;j++){
    
    
        for(int k=j+1;k<i;k++){
    
    
            if(cmp(a[j],a[k])){
    
    
                t=a[j];
                a[j]=a[k];
                a[k]=t;
            }
        }
    }

    for(int j=0;j<i;j++){
    
    
        printf("%-10s %2d %4d\n",a[j].name,a[j].r,a[j].t);
    }

    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44500344/article/details/108205177