1014_排名

// 1014_排名.cpp : 定義控制檯應用程序的入口點。
//題目1014:排名
//時間限制:1 秒內存限制:32 兆特殊判題:否提交:9152解決:2758
//題目描述:
//    今天的上機考試雖然有實時的Ranklist,但上面的排名只是根據完成的題數排序,沒有考慮每題的分值,所以並不是最後的排名。給定錄取分數線,請你寫程序找出最後通過分數線的考生,並將他們的成績按降序打印。
//輸入:
//    測試輸入包含若干場考試的信息。每場考試信息的第1行給出考生人數N ( 0 < N < 1000 )、考題數M ( 0 < M < = 10 )、分數線(正整數)G;第2行排序給出第1題至第M題的正整數分值;以下N行,每行給出一名考生的准考證號(長度不超過20的字符串)、該生解決的題目總數m、以及這m道題的題號(題目號由1到M)。 
//    當讀入的考生人數爲0時,輸入結束,該場考試不予處理。
//輸出:
//    對每場考試,首先在第1行輸出不低於分數線的考生人數n,隨後n行按分數從高到低輸出上線考生的考號與分數,其間用1空格分隔。若有多名考生分數相同,則按他們考號的升序輸出。
//樣例輸入:
//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
//1 2 40
//10 30
//CS001 1 2
//2 3 20
//10 10 10
//CS000000000000000001 0
//CS000000000000000002 2 1 2
//0
//樣例輸出:
//3
//CS003 60
//CS001 37
//CS004 37
//0
//1
//CS000000000000000002 20
//來源:
//2005年浙江大學計算機及軟件工程研究生機試真題

#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"

#define maxN 1001
#define maxM 12
#define maxG 100

struct student{
    char id[22];
    int problem[maxM];  //答對的題目及分值
    int score;         
    int npro;          //答對的題目數
    int isPass;
}student[maxN],student2[maxN];

int compare(const void *p,const void *q)
{
    struct student *p1 = (struct student *)p;
    struct student *q1 = (struct student *)q;
    if((*p1).score == (*q1).score)
        return strcmp((*p1).id,(*q1).id);
    else
        return (*q1).score - (*p1).score;
}

int main()
{
    int N,M,G;
    while(scanf("%d",&N)!=EOF)
    {
        if(!N)
            break;
        else
        {
            int n=0;
            scanf("%d %d",&M,&G);
            int prob[maxM];
            for(int i=1;i<=M;i++)
                scanf("%d",&prob[i]);
            for(int i=1;i<=N;i++)
            {
                student[i].score = 0;
                student[i].isPass = 0;
                scanf("%s %d",student[i].id,&student[i].npro);
                int temp;
                for(int j=1;j<=student[i].npro;j++)
                {
                    scanf("%d",&temp);
                    student[i].score += prob[temp];             
                }
                if (student[i].score>=G)
                {
                    student2[n] = student[i];
                    n++;
                    student[i].isPass = 1;
                }
            }
            qsort(student2,n,sizeof(student2[0]),compare);
            printf("%d\n",n);
            for(int k = 0;k<n;k++)
                printf("%s %d\n",student2[k].id,student2[k].score);
        }
    }
    return 0;
}

發佈了60 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章