A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分)
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
思考
sort第二个参数是尾元素下一个地址,而非尾元素地址。
cmp函数是会写了
AC代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Student {
char id[15];
int score;
int location_number;
int local_rank;
}stu[30010];
/*目的分数降序,那么第一个参数<第二个参数,返回正值
=,返回0
>,返回负值
成绩相同,准考证号升序*/
int cmp(const void* a, const void* b) {
struct Student*aa=(Student*)a;
struct Student*bb=(Student*)b;
// struct Student*aa=a;
// struct Student*bb=b;
if(aa->score != bb->score) return aa->score < bb->score ?1:-1;
else return strcmp(aa->id, bb->id);
}
int main() {
int n, k, num = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &k);
for(int j = 0; j < k; j++) {
scanf("%s %d", stu[num].id, &stu[num].score);
stu[num].location_number = i;
num++;
}
qsort(stu + num - k, k,sizeof (struct Student), cmp);
stu[num - k].local_rank = 1;
for(int j = num - k + 1; j < num; j++) {
if(stu[j].score == stu[j - 1].score) {
stu[j].local_rank = stu[j - 1].local_rank;
} else {
stu[j].local_rank = j + 1 - (num - k);
}
}
}
printf("%d\n", num);
qsort(stu, num ,sizeof (struct Student) ,cmp);
int r = 1;
for(int i = 0; i < num; i++) {
if(i > 0 && stu[i].score != stu[i - 1].score) {
r = i + 1;
}
printf("%s ", stu[i].id);
printf("%d %d %d\n", r, stu[i].location_number, stu[i].local_rank);
}
return 0;
}
A1025 PAT Ranking (25)(25 分)的更多相关文章
- PAT A1025 PAT Ranking(25)
题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- A1025. PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT甲级——A1025 PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT甲级真题 A1025 PAT Ranking
题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- PAT A1025 pat ranking
有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出 #include<iostream> #include<str ...
- PAT_A1025#PAT Ranking
Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- 7-19 PAT Judge(25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
随机推荐
- JavaEE 7 新特性之WebSocket
开发环境: JDK:1.7及以上 JavaEE:1.7,因为只有javaee7才有websocke的api,也可以使用1.6单都导入websocket-api.jar试试(本人不清楚) 注意:没有使用 ...
- AOP注解方式
Aop, aspect object programming 面向切面编程 功能: 让关注点代码与业务代码分离! 关注点, 重复代码就叫做关注点: 切面, 关注点形成的类,就叫切面(类)! 面向切 ...
- android 开发AlertDialog.builder对话框的实现
AndroidAPI提供了Dialog对话框控件,但google明确指出不建议开发者只是使用Dialog来创建对话框,而应该自定义对话框或者使用API中提供的Dialog的子类,如AlertDialo ...
- SpringBoot | 第十章:Swagger2的集成和使用
前言 前一章节介绍了mybatisPlus的集成和简单使用,本章节开始接着上一章节的用户表,进行Swagger2的集成.现在都奉行前后端分离开发和微服务大行其道,分微服务及前后端分离后,前后端开发的沟 ...
- SpringMVC05 return (Json)
这里要主要的是js文件要引入,文中不做解释 1.导入包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...
- 《C#高效编程》读书笔记04-使用Conditional特性而不是#if条件编译
#if/#endif语句常用来基于同一份源代码生成不同的编译结果,其中最常见的就是debug版和release版.但是这在实际应用中并不是非常友好,因为它们容易被滥用,其代码也难以理解或调试. C#为 ...
- jquery jquery中是否加()的问题
自己总结的,慢慢修改再: 1带上()代表立即执行 去掉()代表当有事件发生的时候,我再执行
- vue-cli脚手架构建了项目如何去除Eslint验证(语法格式验证)
Eslint是一个语法检查工具,但是限制很严格,在vue文件里面很多空格都会导致红线,取消的方式如下: 1.创建工程的时候,提示是否启用eslint检测的. Use ESLint to lint yo ...
- Android-->RxJava2更新体验
截止日前最新版2017-3-15: RxJava compile ‘io.reactivex:rxjava:’ compile ‘io.reactivex:rxandroid:’ RxJava2 co ...
- WPF样式学习三
SnapsToDevicePixels 获取或设置在呈现过程,该值来确定呈现此元素是否应使用特定于设备的像素设置. 这是一个依赖项属性. true ,如果元素应以符合呈现到设备像素;否则, false ...