id用int,避免了id的strcmp,不然用string就超时。

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int n,c;
struct student{
int id;
char name[10];
int grade;
};
vector<student> stu;
bool cmp(student a,student b){
if(c==1){
return a.id<b.id;
}else if(c==2){
if(strcmp(a.name,b.name)!=0){
return strcmp(a.name,b.name)<0;
}else{
return a.id<b.id;
}
return 0; }else if(c==3){
if(a.grade!=b.grade){
return a.grade<b.grade;
}else{
return a.id<b.id;
}
}
return 0;
} int main(){
cin>>n>>c;
for(int i=0;i<n;i++){
student s;
scanf("%d%s%d",&s.id,s.name,&s.grade);
stu.push_back(s);
}
sort(stu.begin(),stu.end(),cmp);
std::vector<student>::iterator v=stu.begin();
while(v!=stu.end()){
printf("%06d %s %d\n",v->id,v->name,v->grade);
v++;
}
return 0;
}

PAT1028. List Sorting (25)的更多相关文章

  1. PAT1028. List Sorting (25)---strcmp

    题目链接为:https://www.patest.cn/contests/pat-a-practise/1028 1028. List Sorting (25) Excel can sort reco ...

  2. PAT 解题报告 1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...

  3. PAT1028:List Sorting

    1028. List Sorting (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Excel ca ...

  4. 【PAT】1052 Linked List Sorting (25)(25 分)

    1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...

  5. Pat 1052 Linked List Sorting (25)

    1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  6. pat1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  7. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

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

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

  9. 【PAT】1028. List Sorting (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...

随机推荐

  1. (分享)Linux服务器如何防止中木马

    大家的windows机器可能经常装一些杀毒软件或者什么的来防止中毒,然而在Linux上我们应该怎么防止这些呢? 在面试过程中我们也经常遇到该类问题,那么我们应该怎么回答才显得既有逻辑又有深度呢? 首先 ...

  2. 1307 绳子与重物(DFS)

    1307 绳子与重物 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 有N条绳子编号 0 至 N - 1,每条绳子后面栓了一个重物重量 ...

  3. 介绍一下Python中webbrowser的用法?

    webbrowser模块提供了一个高级接口来显示基于Web的文档,大部分情况下只需要简单的调用open()方法.webbrowser定义了如下的异常:exception webbrowser.Erro ...

  4. Linux中的正则表达式

    *               前一个字符匹配0次或任意次.               匹配除了换行符外任意一个字符^              匹配行首$              匹配行尾[] ...

  5. (4.11)sql server内存使用

    一些内存使用错误理解   开篇小感悟 在实际的场景中会遇到各种奇怪的问题,为什么会感觉到奇怪,因为没有理论支撑的东西才感觉到奇怪,SQL Server自己管理内存,我们可以干预的方式也很少,所以日常很 ...

  6. 003-搭建框架-实现IOC机制

    一.实现目标 一种MVC[Model-View-Controller]一种设计模式,进行解耦. /* * 处理客户管理相关请求 */ @Controller public class Customer ...

  7. mysql数据库中表记录的玩法

    一.增加表记录(相当于插入表记录) 1. 插入完整数据(顺序插入) 语法一: INSERT INTO 表名(字段1,字段2,字段3…字段n) VALUES(值1,值2,值3…值n); 语法二: INS ...

  8. Computer Information

    Lab: lxw@lxw-PC:python$ df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda7 190G .4G 175G % / none .0K .0K % /sys/ ...

  9. Summaries On Java

    @1:== 和 equals(): ==用于比较引用和比较基本数据类型时具有不同的功能: 比较基本数据类型:如果两个值相同,则结果为true. 比较引用:如果引用指向内存中的同一对象,结果为true( ...

  10. MySQL数据库(8)_MySQL数据库总结

    sql语句规范 sql是Structured Query Language(结构化查询语言)的缩写.SQL是专为数据库而建立的操作命令集,是一种功能齐全的数据库语言. 在使用它时,只需要发出“做什么” ...