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 ...
随机推荐
- 山石防火墙debug
debug dp basic debug dp snoop debup dp drop debug dp filter src-ip ? show logging debug
- IOS学习笔记(五)——UI基础UIWindow、UIView
在PC中,应用程序多是使用视窗的形式显示内容,手机应用也不例外,手机应用中要在屏幕上显示内容首先要创建一个窗口承载内容,iOS应用中使用UIWindow.UIView来实现内容显示. UIWindow ...
- bsd socket 网络通讯必备工具类
传输数据的时候都要带上包头,包头有简单的又复杂的,简单的只要能指明数据的长度就够了. 这里我写了一个工具类,可以方便地将整型的数据长度转换为长度为 4 的字节数组. 另一方面,可以方便的将长度为 4 ...
- 【BZOJ2506】calc 分段+vector+莫队
[BZOJ2506]calc Description 给一个长度为n的非负整数序列A1,A2,…,An.现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且A ...
- 安装和配置jenkins
1.首先准备java环境,安装JDK 2.下载jenkins至Linux服务器 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkin ...
- Python3.6全栈开发实例[020]
20.判断一个数是否是水仙花数, 水仙花数是一个三位数, 三位数的每一位的三次方的和还等于这个数. 那这个数就是一个水仙花数, 例如: 153 = 1**3 + 5**3 + 3**3 num = i ...
- 我的Android进阶之旅------>Android知识图谱
Android知识图谱,快来看看哪方面有漏洞? 该图转自:http://blog.csdn.net/xyz_lmn/article/details/41411355
- Insert Buffering
14.5.13.4 Insert Buffering Database applications often insert new rows in the ascending order of the ...
- graoovy资料
官网 http://www.groovy-lang.org/ 官方文档 http://www.groovy-lang.org/documentation.html Groovy入门教程 http:// ...
- springMVC文件的上传与下载
1.文件上传 springmvc中只需要配置上传组件,然后配合使用MultipartFile,就可以轻松实现单个文件上传和批量上传,而且上传的文件类型和大小都可以在springmvc 配置文件中配置. ...