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. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)3.1——使用Build Types

    问题: 你想要自定义debug和release的build types,并且新建一些新的types. 解决方案: 使用buildTypes块配置build types. 讨论: build type决 ...

  2. selenium的元素定位-鼠标事件

    鼠标事件 ActionChains 类提供了鼠标操作的常用方法: perform(): 执行所有 ActionChains 中存储的行为: context_click(): 右击: double_cl ...

  3. <转> python的垃圾回收机制

    Python的GC模块主要运用了“引用计数”(reference counting)来跟踪和回收垃圾.在引用计数的基础上,还可以通过“标记-清除”(mark and sweep)解决容器对象可能产生的 ...

  4. 【BZOJ2005】[Noi2010]能量采集 欧拉函数

    [BZOJ2005][Noi2010]能量采集 Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把 ...

  5. EasyNVR摄像机无插件直播进行摄像机云台控制的接入及调用详解

    EasyNVR云台接入及控制详解 摄像机云台控制在摄像机当中很常见摄像机能将当前状态下云台的水平角度.倾斜角度和摄像机镜头焦距等位置参数存储到设备中,需要时可以迅速调用这些参数并将云台和摄像头调整至该 ...

  6. linux中常见的文件操作命令

    由于经常在linux发布工程进行测试,所以要用到linux一些文件操作命令,再此进行总结,以便以后忘记的时候查看. 改变目录:cd 回到家目录 cd或者cd~ 查看当前目录:pwd 查看目录下的文件的 ...

  7. 数据链路层负载均衡 Linux Virtual Server

    w 李智慧

  8. 前端之 JS 实现全选、反选、取消选中

    需求 制作如下可选表格,实现“全选”.“反选”.“取消”功能 代码示例 <!DOCTYPE html> <html lang="zh-CN"> <he ...

  9. git读取配置文件的顺序

    a.查找系统配置文件: /etc/gitconfig 文件,该文件含有系统里每位用户及他们所拥有的仓库的配置值 b.查找用户配置文件:  ~/.gitconfig  文件 或者  ~/.config/ ...

  10. 剑指offer 面试27题

    面试27题: 题目:二叉树的镜像 题:操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / ...