PAT1028. List Sorting (25)
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)的更多相关文章
- PAT1028. List Sorting (25)---strcmp
题目链接为:https://www.patest.cn/contests/pat-a-practise/1028 1028. List Sorting (25) Excel can sort reco ...
- PAT 解题报告 1052. Linked List Sorting (25)
1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...
- PAT1028:List Sorting
1028. List Sorting (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Excel ca ...
- 【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 ...
- Pat 1052 Linked List Sorting (25)
1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- pat1052. Linked List Sorting (25)
1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not ne ...
- PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed to i ...
- 【PAT】1028. List Sorting (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...
随机推荐
- iOS Document Interaction 编程指南
本文转载至 http://www.2cto.com/kf/201306/219382.html iOS支持在你的app中用其他app预览和显示文档.iOS还支持文件关联,允许其他app通过你的程序打开 ...
- Android系统中Parcelable和Serializable的区别,自动化实现Parcelable接口的插件
Parcelable和Serializable的区别 参考地址:http://greenrobot.me/devpost/android-parcelable-serializable/ 由于最终的区 ...
- 使用jquery-tmpl使JavaScript与HTML分离
背景:由于对JavaScript字符串拼接JavaScript变量产生了反感,也想用用JavaScript模板库,看了几个,由于时间原因选择了jQuery.tmpl.js,因为Visual Studi ...
- Gcc手册(转)
手册链接地址:http://www.shanghai.ws/gnu/gcc_1.htm GCC中文手册 GCC现在是GNU中最主要和最流行的c & c++编译器. gcc/g++在执行编译工作 ...
- make tree install 目录树状结构工具安装
http://futeng.iteye.com/blog/2071867 http://zhou123.blog.51cto.com/4355617/1196415 wget ftp://mama.i ...
- 印象笔记windows端-快捷键大全
作为印象笔记粉,当然要多掌握些快捷键,提高办公效率. 补: ctrl + shift + , 光标内字体变小 ctrl + shitf + . 光标内字体变大
- github常用的git命令
添加已有项目到github: touch README.md //新建说明文件 git init //在当前项目目录中生成本地git管理,并建立一个隐藏.git目录 git add . //添加当前目 ...
- springboot添加对listener,servlet,filter的支持
比较常用的方式就是使用注解来添加对 监听器,过滤器,servlet的支持. 1.首先在启动类上添加 @ServletComponentScan 开启 对监听器,过滤器,servlet的注解扫描. ...
- oracle11g参数的简单查看方法
1.查看processes和sessions参数show parameter processesshow parameter sessions 2.修改processes和sessions值alter ...
- 小计---pandas读取带有中文文件名或者包含中文内容的文件
python2下: # -*- coding: utf-8 -*- import pandas as pd mydata = pd.read_csv(u"例子.csv") #前面加 ...