题意:

输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数)。输出排序后的信息,排序根据C决定。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct student{
string id,name;
int grade;
};
student s[];
bool cmp(student a,student b){
return a.id<b.id;
}
bool cmp2(student a,student b){
if(a.name!=b.name)
return a.name<b.name;
return a.id<b.id;
}
bool cmp3(student a,student b){
if(a.grade!=b.grade)
return a.grade<b.grade;
return a.id<b.id;
}
int main(){
int n,c;
cin>>n>>c;
for(int i=;i<=n;++i)
cin>>s[i].id>>s[i].name>>s[i].grade;
if(c==)
sort(s+,s++n,cmp);
else if(c==)
sort(s+,s++n,cmp2);
else if(c==)
sort(s+,s++n,cmp3);
for(int i=;i<=n;++i){
cout<<s[i].id<<" "<<s[i].name<<" "<<s[i].grade;
cout<<((i==n)?"":"\n");
}
return ;
}

【PAT甲级】1028 List Sorting (25 分)的更多相关文章

  1. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  2. PAT 甲级 1028. List Sorting (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...

  3. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  4. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  5. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  6. PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

    1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be ...

  7. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

    1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime ...

  8. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  9. PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)

    1048 Find Coins (25 分)   Eva loves to collect coins from all over the universe, including some other ...

  10. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

随机推荐

  1. matlab 绘制原始信号的谐波

    这里以锯齿信号为例: clear;clc; figure time = 0:1/20:1000; wave = sawtooth(time); subplot(3, 1, 1); plot(time, ...

  2. nodejs的req取参req.body,req.params,req.query

    1/req.query: Get:/domo?name=ximiximi&blog=https://home.cnblogs.com/u/ximiximi-blog/ app.get('/do ...

  3. opencv:图像的读取,显示,写入文件

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  4. Raid5(五块磁盘,三块做raid,两块做备份)

    1.在虚拟中再添加五块磁盘.  2.使用mdadm命令创建raid5,名称为“/dev/md5”. -C代表创建操作,-v显示创建过程,-a yes检查RAID名称,-n是用到的硬盘个数,-l是定义R ...

  5. 【PAT甲级】1083 List Grades (25 分)

    题意: 输入一个正整数N(<=101),接着输入N个学生的姓名,id和成绩.接着输入两个正整数X,Y(0<=X,Y<=100),逆序输出成绩在x,y之间的学生的姓名和id. tric ...

  6. jsp用equals判断两个字符串变量是否相等

    使用即可: s1.equals(s2) 如果使用场景: if(s1==s2){} 这样使用可能会出现判断无效的情况. 使用if(s1.equals(s2)){}就可以了.

  7. 3_6 环状序列(UVa1584)

    长度为n的环状串有n种表示法,分别为某个位置开始顺时针得到.例如,图中的环状串有10种表示: CGAGTCAGCT,GAGTCAGCTC,AGTCAGCTCG等.在这些表示法中,字典序最小的称为“最小 ...

  8. byte的取值范围

    byte b = Byte.MAX_VALUE;        b+=1;        System.out.println(b); //输出为-128 取值范围为[-128 -  127] 解析: ...

  9. 24 JavaScript对象访问器&JavaScript对象构造器

    ES5引入了Getter和Setter Getter和Setter允许定义对象访问器 JavaScript Getter(get关键字):获取对象属性 <script> var perso ...

  10. BGP前缀过滤(正则表达式)

    BGP的正则表达式一般用在as-path中,常用的如下: .(点):表示匹配任意一个字符,包括空格. *:表示匹配零个或多个模式的出现.即前一个字符出现0次或多次. +:表示匹配一个或多个模式的出现. ...