zoukankan      html  css  js  c++  java
  • PAT 1025 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 N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K 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 N. 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
    

    思路

    注意排名的时候,相同等级,要按照id字符串来排序。

    代码

    #include <stdio.h>
    #include <string>
    #include <stdlib.h>
    #include <iostream>
    #include <vector>
    #include <string.h>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <queue>
    #include <stack>
    #include <functional>
    #include <limits.h> 
    using namespace std;
    struct node{
    	string id;
    	int loc;
    	int sc;
    	int ord[2]; // 0 全部排名  1 本组排名 
    	node(){
    		
    	} 
    	node(string _id, int _loc, int _sc){
    		id = _id;
    		loc = _loc;
    		sc = _sc;
    	}
    };
    int N;
    int sum = 0;// 记录总共人数 
    vector<node> myv;
    
    bool cmp(node a, node b){
    	if(a.sc > b.sc)	return true;
    	else if(a.sc == b.sc)	return a.id < b.id;
    	else return false;
    }
    
    
    void prop(int pos, int index){
    	myv[pos].ord[index] = 1;
    	int order = 2;
    	for(int i = pos + 1; i < myv.size(); i++){
    		if(myv[i].sc == myv[i - 1].sc){
    			myv[i].ord[index] = myv[i - 1].ord[index];
    		}
    		else{
    			myv[i].ord[index] = order;
    		}
    		order++;
    	}
    }
    
    int main() {
    	cin >> N;
    	for(int i = 1;i <= N; i++){
    		int t;
    		cin >> t;
    		
    		string id;
    		int sc;
    		for(int j = 1; j <= t; j++){
    			cin >> id >> sc;
    			myv.push_back(node(id, i, sc));
    		}
    		sort(myv.begin() + sum, myv.end(), cmp);
    		prop(sum, 1);
    		sum += t; 
    	}
    	cout << sum << endl;
    	sort(myv.begin(), myv.end(), cmp);
    	prop(0, 0);
    	for(int i = 0; i < myv.size(); i++){
    		cout << myv[i].id << " " << myv[i].ord[0] << " " << myv[i].loc << " " << myv[i].ord[1] << endl;
    	}
    	return 0; 
    }
    
    
  • 相关阅读:
    Ubuntu下Chromium for Android 源码的编译
    Ubuntu下编译Chromium for Android
    解决Inno Setup制作安装包无法创建桌面快捷方式的问题
    linux下验证码无法显示:Could not initialize class sun.awt.X1 解决方案
    在ubuntu 14.04 64位系统上安装32位库
    zxing实现二维码生成和解析
    H264码流打包分析
    YUV格式&像素
    谈谈“色彩空间表示方法”——RGB、YUY2、YUYV、YVYU、UYVY、AYUV
    RTP与RTCP协议介绍
  • 原文地址:https://www.cnblogs.com/woxiaosade/p/12422186.html
Copyright © 2011-2022 走看看