• A1025 PAT Ranking


    题目描述

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains a positive number  (), the number of test locations. Then  ranklists follow, each starts with a line containing a positive integer  (), the number of testees, and then  lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

    registration_number final_rank location_number local_rank
    
     

    The locations are numbered from 1 to . The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

    Sample Input:

    2
    5
    1234567890001 95
    1234567890005 100
    1234567890003 95
    1234567890002 77
    1234567890004 85
    4
    1234567890013 65
    1234567890011 25
    1234567890014 100
    1234567890012 85
    
     

    Sample Output:

    9
    1234567890005 1 1 1
    1234567890014 1 2 1
    1234567890001 3 1 2
    1234567890003 3 1 2
    1234567890004 5 1 4
    1234567890012 5 2 2
    1234567890002 7 1 5
    1234567890013 8 2 3
    1234567890011 9 2 4

    代码

    #include<iostream>
    #include<string>
    #include<algorithm>
    using namespace std;
    
    struct Student {
    	string number;  //考号
    	int score;  //成绩
    	int r; //考场内排名
    	int location_num; //考场号
    }stu[30010];
    
    bool cmp(Student a, Student b) {
    	if (a.score != b.score) return a.score > b.score;
    	else return a.number < b.number;
    }
    int main() {
    	int N; //考场数
    	int K; //选手数
    	int num=0; //选手总数
    
    	cin >> N; //共有多少个考场
    	for (int i = 1; i <= N; i++) {
    		cin >> K;
    		for (int j = 1; j <= K; j++) {
    			cin >> stu[num].number >> stu[num].score;
    			stu[num].location_num = i;
    			num++; //总考生数加1
    		}
    
    		sort(stu + num - K, stu + num, cmp); //将该考场的考生排序
    		stu[num - K].r = 1;  //该考场第一名的场内排名记作1
    		for (int j= num - K + 1; j< num; j++) { //对该考场剩余的学生
    			if (stu[j].score == stu[j - 1].score)
    				stu[j].r = stu[j - 1].r;
    			else
    				stu[j].r = j + 1 - (num - K);
    		}
    	}
    	cout << num << endl;; //输出总考生数
    	sort(stu, stu + num, cmp);
    	int r = 1;
    	for (int i = 0; i < num; i++) {
    		if (i > 0 && stu[i].score != stu[i - 1].score)
    			r = i + 1;  //当前考生与上一个考生分数不同时,让r更新为人数+1
    		cout << stu[i].number << " " << r << " " << stu[i].location_num << " " << stu[i].r << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    solr部署长命版后继
    reiserfs相关
    sqlite in python
    查看文件系统
    https://wiki.fourkitchens.com/dashboard.action这个技术wiki不错
    gvim菜单显示问题
    linux tips
    solr部署一气呵成版,让你多活两天
    挺好玩的C语句
    hardy ubuntu source list
  • 原文地址:https://www.cnblogs.com/ltw222/p/16097239.html
Copyright © 2020-2023  润新知