题目链接

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. phpexcel常用操作

    $objPHPExcel = new PHPExcel();//设置列宽$objPHPExcel->getActiveSheet()->getColumnDimension('A')-&g ...

  2. php字符串实例

    2.双引号字符串 <?php print "I have gone to the store."; print "The sauce cost \$10.25.&q ...

  3. numpy基础语法

    np.zeros(5) [ 0.  0.  0.  0.  0.] 所得类型为数组, numpy.zeros_like(a, dtype=None, order='K', subok=True) 生成 ...

  4. linux使用tar命令打包压缩时排除某个文件夹或文件

    今天在使用tar命令进行文件夹打包压缩的时候,需要打包压缩masalaPage目录,但是该目录中的2017,2016两个目录中的文件不进行打包压缩 所以通常使用的tar -zcvf masalaPag ...

  5. 【前端阅读】——《程序员思维修炼》摘记&读后感&思维导图

    前言:这是一本介绍如何用脑的书,并从思维的角度(以程序员为例),介绍如何从新手成为专家.作者带领着读者(我)共同经历一次有关认知科学.神经学.学习和行为理论的旅程,探索人类大脑令人 惊奇的工作的机制, ...

  6. SourceTree的基本使用-git on mac

    SourceTree的基本使用 学习了:https://www.cnblogs.com/tian-xie/p/6264104.html

  7. 转: php实现的开源电商网站

    转:http://www.magentochina.org/what-is-magento

  8. 关于阿里 weex 的使用与案例

    1. 阿里宣布开源Weex http://mp.weixin.qq.com/s?__biz=MzA4MjA0MTc4NQ==&mid=504089541&idx=1&sn=3a ...

  9. 记一个发HTML格式邮件的问题

    很早做了一个自动发邮件的程序,前一向发现Notes升级后反而CSS样式都没有了. 起初不以为意,反正格式数据在,客户也没说啥,后来觉得这样的态度要不得,小洞不补,大洞吃苦. 于是查查资料,发现浏览器里 ...

  10. [ACM] HDU 5024 Wang Xifeng&#39;s Little Plot (构造,枚举)

    Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of ...