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. 数据类型比较:Long和BigDecimal

    1.基本类型: 基本类型可以用:">" "<" "==" 2.基本类型包装类:(对象类型) 2.1 Long 型: 要比较两个L ...

  2. 用JS改变的元素CSS样式,css里display :none 隐藏 block 显示

    CSS样式的引用有3种方式:style引用.class引用.id引用,所以js改变元素的样式我们也分3种来说. 1.js改变由style方式引用的样式:方法一:document.divs.style. ...

  3. java中的四种权限

    1.私有权限(private) private可以修饰数据成员,构造方法,方法成员,不能修饰类(此处指外部类,不考虑内部类).被private修饰的成员,只能在定义它们的类中使用,在其他类中不能调用. ...

  4. 高德地图API使用

    1.根据地址找经纬度/修改经纬度 marker.setPosition(result.geocodes[0].location); map.setCenter(marker.getPosition() ...

  5. Vue.js中css的作用域

    Vue.js中的css的作用域问题: 如果在vue组件下的style中定义样式,效果会作用于整个html页面,如果只想本组件的css样式只作用于本组件的话,在<style>标签里添加sco ...

  6. 阿里云RDS上的一些概念性记录

    刚接触RDS,只能对RDS上的一些特性做一些笔记,方便记忆,以下为RDS上的内容摘录,取自官方文档 1 数据备份 可使用命令行或图形界面进行逻辑数据备份.仅限通过 RDS 管理控制台 或 OPEN A ...

  7. 023-Spring Boot 服务的注册和发现

    一.概述 服务调用 1.1.nginx方式 1.2.注册中心 二.注册中心[zookeeper] 2.1.安装zookeeper3.4.11 2.2.服务提供方,需要在服务启动时吗.,把服务的信息(I ...

  8. springMVC文件的上传与下载

    1.文件上传 springmvc中只需要配置上传组件,然后配合使用MultipartFile,就可以轻松实现单个文件上传和批量上传,而且上传的文件类型和大小都可以在springmvc 配置文件中配置. ...

  9. oracle11g参数的简单查看方法

    1.查看processes和sessions参数show parameter processesshow parameter sessions 2.修改processes和sessions值alter ...

  10. 小计---pandas读取带有中文文件名或者包含中文内容的文件

    python2下: # -*- coding: utf-8 -*- import pandas as pd mydata = pd.read_csv(u"例子.csv") #前面加 ...