1197: Exam Ranking (1) (structure topic)

1197: Exam Ranking (1) (structure topic)

Item description
The computer-based exam for Zhejiang University's postgraduate re-examination today is similar to the scoring rules of the traditional written exam. There are a total of n questions, each question has a corresponding score, and the final score is calculated. Now given the admission score, please write a program to find out the candidates who passed the score last, and print their scores in descending order.
Input
The first line gives the number of candidates N ( 1<= N<=100 ), the number of test questions M (1<=M<=10 ), and the fractional line (positive integer) G;
the second line is sorted to give the first question to the first Positive integer score for question M; in
the following N lines, each line gives a test taker's admission ticket number (a string not exceeding 20), the total number of questions solved by the student, m, and the question number of the m questions
( The topic number is from 1 to M).
Output
First, output the number n of candidates who are not lower than the score line on the first line, and then output the test numbers and scores of the online candidates in order of scores from high to low on n lines, separated by 1 space. If there are multiple candidates with the same score, they will be output in ascending order of their test numbers.
Sample Input Copy
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
Sample Output Copy
3
CS003 60
CS001 37
CS004 37
Source/Classification

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

typedef struct student{
    
    
    char id[21];
    int m;
    int sum;//总分
}student;

int cmp(student a,student b){
    
    
    if(a.sum<b.sum)  return 1;
    if(a.sum==b.sum&&strcmp(a.id,b.id)>0) return 1;
    return 0;
}

int main(){
    
    
    int N,M,G;
    int s[10],g,count=0;
    student stu[100],t;
    
    scanf("%d %d %d",&N,&M,&G);
    for(int i=0;i<M;i++){
    
    
        scanf("%d",&s[i]);
    }

    
    for(int i=0;i<N;i++){
    
    
        scanf("%s %d",stu[i].id,&stu[i].m);
        stu[i].sum=0;//初始化为0
        for(int j=0;j<stu[i].m;j++){
    
    
            scanf("%d",&g);//输入题号,题号要减1
            stu[i].sum+=s[g-1];
        }
        if(stu[i].sum>=G) count++;
    }
    //排序
    for(int i=0;i<N-1;i++){
    
    
        for(int j=i+1;j<N;j++){
    
    
            if(cmp(stu[i],stu[j])){
    
    
                t=stu[i];
                stu[i]=stu[j];
                stu[j]=t;
            }
        }
    }

    printf("%d\n",count);
    for(int i=0;i<N;i++){
    
    
        if(stu[i].sum>=G) printf("%s %d\n",stu[i].id,stu[i].sum);
    }
    return 0;
}

Guess you like

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