2977. 成绩排序

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

typedef struct {
    int score;
    char id[12];
} Student;

int cmp(void const *_a, void const *_b) {
    Student const *a = (Student const *)_a;
    Student const *b = (Student const *)_b;
    if (a->score == b->score)
        return strcmp(a->id, b->id);
    return b->score - a->score;
}

int main() {
    int t;
    scanf("%i", &t);
    for (int i = 0; i < t; ++i) {
        int n, m, g;
        scanf("%i%i%i", &n, &m, &g);

        int points[11];
        for (int j = 1; j <= m; ++j)
            scanf("%i", &points[j]);

        Student students[500];
        for (int j = 0; j < n; ++j) {
            int s;
            students[j].score = 0;
            scanf("%s%i", students[j].id, &s);
            for (int k = 0; k < s; ++k) {
                int solve;
                scanf("%i", &solve);
                students[j].score += points[solve];
            }
        }
        qsort(students, n, sizeof(Student), cmp);

        int passed = 0;
        while (students[passed].score >= g)
            ++passed;
        printf("case #%i:\n%i\n", i, passed);

        for (int j = 0; j < passed; ++j)
            printf("%s %i\n", students[j].id, students[j].score);
    }
}
Li Dao

AC程序+要点
结构体排序,做的不做了

include

using namespace std;
struct Stu
{
string SID;
int score;
};
vector questions;
vector students;
int n,m,g,T;
int cmp(const Stu& aa,const Stu& bb)
{
if(aa.score!=bb.score) return aa.score>bb.score;
else return aa.SID>T;
for(int step=0;step>n>>m>>g;
for(int i=1;i<=m;i++)
{
int xx;cin>>xx;
questions.push_back(xx);
}
for(int i=1;i<=n;i++)
{
string sid;
int s,Score=0;
cin>>sid>>s;
for(int i=1;i<=s;i++)
{
int xx;cin>>xx;
Score+=questions[xx-1];
}
if(Score>=g) students.push_back((Stu){sid,Score});
}
sort(students.begin(),students.end(),cmp);
printf(“case #%d:\n”,step);
cout<<students.size()<<endl;
for(int i=0;i<students.size();i++)
cout<<students[i].SID<<’ ‘<<students[i].score<<endl;
}
return 0;
}

Sanity

include

include

include

typedef struct
{
char id[12];
int num;
int grade;
} Student;

int cmp(const voida,const voidb)
{
Studentaa=(Student)a;
Studentbb=(Student)b;
int t;
t=bb->grade-aa->grade;
if(t!=0)
return t;
else
return strcmp(aa->id,bb->id);
}

int main()
{
Student s[502];
int T,t;
int a[16];
scanf(“%d”,&T);
for(t=0; t<T; t++)
{
int N,M,G,i,j,temp;
int count=0;
scanf(“%d%d%d”,&N,&M,&G);
for(i=0; i<M; i++)
{
scanf(“%d”,&a[i]);
}
for(i=0; i<N; i++)
{
scanf(“%s%d”,s[i].id,&s[i].num);
s[i].grade=0;
for(j=0; j=G) count++; printf("case #%d:\n%d\n",t,count); if(s[0].grade>=G)
printf(“%s %d\n”,s[0].id,s[0].grade);
for(i=1; i=G)
printf(“%s %d\n”,s[i].id,s[i].grade);
}
return 0;
}

你当前正在回复 博客/题目
存在问题!