这道题是照着晴神的来敲,但是自己技术太渣,中间还是出现了不少问题。

1.学习到排序的做法,利用algorithm库的sort(begin,end,cmp),自己按照题目要求来完成cmp的编写

可能经常会用到cstring库的strcmp(a,b),是个好东西,a>b返回正数,==返回0,小于返回负数

2.如果排序题中的个体是有很多用于排序的私人信息的话,可以使用struct来囊括

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
struct student{
char rn[]; //准考号
int score; //分数
int ln; //场次号
int lr; //本场排名
}; student stu[]; bool cmp(const student &a,const student &b){
if(a.score!=b.score) return a.score>b.score;
else return strcmp(a.rn,b.rn)<; //准考号小的排在前面
} int main(){
freopen("in.txt","r",stdin); int n,num=; //n为考场的数量,num为总人数
scanf("%d",&n); for(int i=;i!=n+;++i){
int k; //本场人数
scanf("%d",&k);
for(int j=;j!=k;++j){
scanf("%s %d",stu[num].rn,&stu[num].score);
stu[num].ln=i;
num++;
} sort(stu+num-k,stu+num,cmp); //当前场次排序
stu[num-k].lr= ;
for(int j=;j!=k;j++){
if(stu[num-k+j].score==stu[num-k+j-].score)
stu[num-k+j].lr=stu[num-k+j-].lr;
else stu[num-k+j].lr=j+;
}
}
printf("%d",num);
sort(stu,stu+num,cmp);
int r=;
for(int i=;i!=num;i++){
printf("\n");
if(i!= && stu[i].score!=stu[i-].score)
r=i+;
printf("%s %d %d %d",stu[i].rn,r,stu[i].ln,stu[i].lr);
} return ;
}

PAT1025的更多相关文章

  1. 课堂作业二 PAT1025 反转链表

    MyGitHub 终于~奔溃了无数次后,看到这个结果 ,感动得不要不要的::>_<:: 题目在这里 题目简述:该题可大致分为 输入链表 -> 链表节点反转 -> 两个步骤 输入 ...

  2. PAT1025. PAT Ranking

    /因为这道题之前做过一次,看了别人的算法思想用local跟galobal排序并插入,所以一写就是照着这个思想来的,记得第一次做的时候用sort分段排序,麻烦要记录起始位置,好像最后还没A,这次用别人的 ...

  3. pat1025. PAT Ranking (25)

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  4. PAT 1025 反转链表

    PAT (Basic Level) Practise 1025 Github链接:https://github.com/H-BING/object-oriented/tree/master/PAT10 ...

  5. [Assignment] C++2

    作业要求:PAT1025 翻转链表 代码在这里

随机推荐

  1. Configuration system failed to initialize

    引用:https://cloud.tencent.com/developer/article/1336954 重装.net Framework

  2. MangoDB

    <MongoDB权威指南> 一.简介 MongoDB是一款强大.灵活.且易于扩展的通用型数据库 1.易用性 MongoDB是一个面向文档(document-oriented)的数据库,而不 ...

  3. 微信小程序之 语言特点

    主页面的CSS样式默认为index.wxss,无需引入

  4. Intellij热部署插件JRebel的详细配置及图解

    参考博客地址:https://blog.csdn.net/nyotengu/article/details/80629631 参考博客地址:https://blog.csdn.net/weixin_4 ...

  5. jira7.3.6 linux安装及破解

    一.环境准备 jira7.3的运行是依赖java环境的,也就是说需要安装jdk并且要是1.8以上版本,如下: http://www.oracle.com/technetwork/java/javase ...

  6. 027 Android 可扩展的listview:ExpandableListView的使用案例

    1.ExpandableListView简介 ExpandableListView是一种用于垂直滚动展示两级列表的视图,和 ListView 的不同之处就是它可以展示两级列表,分组可以单独展开显示子选 ...

  7. 在 VMware 中安装 MacOS 全记录

    在 VMware 15 中安装 MacOS Mojave 安装文件 下载:Unlocker v3.0 for VMware 15地址:https://github.com/DrDonk/unlocke ...

  8. Centos7部署node

    近期在配置jenkins自动化部署前端项目时,需要使用到npm对前端项目进行构建打包,故这里单独介绍下node的部署. 项目地址:https://nodejs.org/en/download/ 1.下 ...

  9. java8 time包的简单使用

    import com.sun.org.apache.xml.internal.res.XMLErrorResources_tr; import java.text.DateFormat; import ...

  10. [C++] 习题 2.18 倒序查找字串

    目录 前置技能 字符串 KMP 算法 需求描述 概要设计 具体实现 string.cpp strmatching.cpp main.cpp 倒序查找字串: 设计一个算法,在串 str 中查找字串 su ...