题目链接

https://www.patest.cn/contests/pat-a-practise/1028

思路

就按照 它的三种方式 设计 comp 函数 然后快排就好了

但是 如果用 c++ 中的 string 保存名字的话 就会超时

所以 用 c 里面的 char *s 就可以过

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7; struct Node
{
int id, g;
char name[10];
}a[maxn]; bool comp_1(Node x, Node y)
{
return x.id < y.id;
} bool comp_2(Node x, Node y)
{
if (strcmp(x.name, y.name) == 0)
return x.id < y.id;
return strcmp(x.name, y.name) > 0 ? 0 : 1;
} bool comp_3(Node x, Node y)
{
if (x.g == y.g)
return x.id < y.id;
return x.g < y.g;
} int main()
{
int n, c;
scanf("%d%d", &n, &c);
for (int i = 0; i < n; i++)
scanf("%d%s%d", &a[i].id, &a[i].name, &a[i].g);
if (c == 1)
sort(a, a + n, comp_1);
else if (c == 2)
sort(a, a + n, comp_2);
else if (c == 3)
sort(a, a + n, comp_3);
for (int i = 0; i < n; i++)
printf("%06d %s %d\n", a[i].id, a[i].name, a[i].g);
}

PAT 甲级 1028. List Sorting (25) 【结构体排序】的更多相关文章

  1. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  2. 【PAT】1028. List Sorting (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...

  3. PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)

    Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...

  4. PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...

  5. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 第m大的身份证号码(局部排序代全局、结构体排序)

    第m大的身份证号码(点击) 时间限制: 1 Sec  内存限制: 128 MB                                                             ...

  8. 转载 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

    转载自:http://www.cnblogs.com/cj695/p/3863142.html sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在 ...

  9. 【转】 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

    sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能 ...

随机推荐

  1. go --socket通讯(TCP服务端与客户端的实现)

    这篇文章主要使用Go语言实现一个简单的TCP服务器和客户端.服务器和客户端之间的协议是 ECHO, 这个RFC 862定义的一个简单协议.为什么说这个协议很简单呢, 这是因为服务器只需把收到的客户端的 ...

  2. PathInterpolator

    PathInterpolator 在v4 support library:Revision 22.1.0的时候,Google在兼容库中增加了几个新的类,用于创建更加真实的动画效果. Added the ...

  3. tomcat 登录时用户名和密码问题

    在编程的时候我们经常在myeclipes中直接部署web程序,大多数情况下不会登陆tomcat,这样时间长了我们就忘记了tomcat的登陆用户名和密码,下面就说一下怎么找到tomcat的用户名和密码吧 ...

  4. selenium遇到不可编辑input和隐藏input如何赋值

    js = 'document.getElementsByName("m:csr_mt_gnccspjclfbxd:bmshldID")[0].type="text&quo ...

  5. Elite Container DELPHI下的一个轻量级IoC对象容器

    一.简介: Elite Container是DELPHI下的一个轻量级IoC对象容器(IoC:Inverse of Control,反转控制).它是参考了Java中的Spring框架(主要是配置文件的 ...

  6. 安装XAMPP时出现 unable to realloc 83886080 bytes

    参考:https://www.apachefriends.org/faq_linux.html 转载:http://blog.xinspace.space/2015/08/06/xampp-unabl ...

  7. 获取服务器classes根路径

    /** * 获取web应用路径 * @Description : 方法描述 * @Method_Name : getRootPath * @return * @return : String * @C ...

  8. JS函数库Underscore.js

    http://underscorejs.org/ http://www.css88.com/doc/underscore/ http://www.bootcss.com/p/underscore/

  9. VueJS渐进式JS框架中文学习

    官方网站:http://vuejs.org/ GitHub:https://github.com/vuejs/vue 中文学习地址:https://cn.vuejs.org/

  10. 当Design Support Library遇上RecycleView

    近期对Design Support Library中的一些新组件做了些研究,当中涉及到CoordinatorLayout.AppBarLayout.CollapsingToolbarLayout,为了 ...