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

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cstring>
  5. using namespace std;
  6. int n,c;
  7. struct student{
  8. int id;
  9. char name[10];
  10. int grade;
  11. };
  12. vector<student> stu;
  13. bool cmp(student a,student b){
  14. if(c==1){
  15. return a.id<b.id;
  16. }else if(c==2){
  17. if(strcmp(a.name,b.name)!=0){
  18. return strcmp(a.name,b.name)<0;
  19. }else{
  20. return a.id<b.id;
  21. }
  22. return 0;
  23.  
  24. }else if(c==3){
  25. if(a.grade!=b.grade){
  26. return a.grade<b.grade;
  27. }else{
  28. return a.id<b.id;
  29. }
  30. }
  31. return 0;
  32. }
  33.  
  34. int main(){
  35. cin>>n>>c;
  36. for(int i=0;i<n;i++){
  37. student s;
  38. scanf("%d%s%d",&s.id,s.name,&s.grade);
  39. stu.push_back(s);
  40. }
  41. sort(stu.begin(),stu.end(),cmp);
  42. std::vector<student>::iterator v=stu.begin();
  43. while(v!=stu.end()){
  44. printf("%06d %s %d\n",v->id,v->name,v->grade);
  45. v++;
  46. }
  47. return 0;
  48. }

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. 山石防火墙debug

    debug dp basic debug dp snoop debup dp drop debug dp filter src-ip ? show logging debug

  2. IOS学习笔记(五)——UI基础UIWindow、UIView

    在PC中,应用程序多是使用视窗的形式显示内容,手机应用也不例外,手机应用中要在屏幕上显示内容首先要创建一个窗口承载内容,iOS应用中使用UIWindow.UIView来实现内容显示. UIWindow ...

  3. bsd socket 网络通讯必备工具类

    传输数据的时候都要带上包头,包头有简单的又复杂的,简单的只要能指明数据的长度就够了. 这里我写了一个工具类,可以方便地将整型的数据长度转换为长度为 4 的字节数组. 另一方面,可以方便的将长度为 4 ...

  4. 【BZOJ2506】calc 分段+vector+莫队

    [BZOJ2506]calc Description          给一个长度为n的非负整数序列A1,A2,…,An.现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且A ...

  5. 安装和配置jenkins

    1.首先准备java环境,安装JDK 2.下载jenkins至Linux服务器 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkin ...

  6. Python3.6全栈开发实例[020]

    20.判断一个数是否是水仙花数, 水仙花数是一个三位数, 三位数的每一位的三次方的和还等于这个数. 那这个数就是一个水仙花数, 例如: 153 = 1**3 + 5**3 + 3**3 num = i ...

  7. 我的Android进阶之旅------>Android知识图谱

    Android知识图谱,快来看看哪方面有漏洞? 该图转自:http://blog.csdn.net/xyz_lmn/article/details/41411355

  8. Insert Buffering

    14.5.13.4 Insert Buffering Database applications often insert new rows in the ascending order of the ...

  9. graoovy资料

    官网 http://www.groovy-lang.org/ 官方文档 http://www.groovy-lang.org/documentation.html Groovy入门教程 http:// ...

  10. springMVC文件的上传与下载

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