题目链接

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. Fresco的使用及注意事项

    Fresco的使用及注意事项 时间 2016-10-17 18:32:12 DevWiki's Blog 原文  http://blog.devwiki.net/index.php/2016/10/1 ...

  2. python遍历当前目录并删除某文件

    #coding: utf-8 """ this programe is to clear driverlog below this dir __author__:the_ ...

  3. winsock 收发广播包 【转】

    winsock 收发广播包 ☛广播包的概念 广播包通常为了如下两个原因使用:1 一个应用程序希望在本地网络中找到一个资源,而应用程序对于该资源的地址又没有任何先验的知识. 2 一些重要的功能,例如路由 ...

  4. Xshell 初次应用

    以前就想安装Xshell,今天终于弄好了,可以在windows下对Linux服务端进行管理. 关于SSH和Xshell的介绍见参考,Linux上安装的是ssh服务端,所以咱们如果希望通过远程访问的方式 ...

  5. 【温故知新】——原生js中常用的四种循环方式

    一.引言 本文主要是利用一个例子,讲一下原生js中常用的四种循环方式的使用与区别: 实现效果: 在网页中弹出框输入0   网页输出“欢迎下次光临” 在网页中弹出框输入1   网页输出“查询中……” 在 ...

  6. C#按指定长度分割字符串

    C#按指定长度分割字符串   这几天学习分析声音的波形数据,接收到的是十六进制的数据,需要将数据转换成十进制再绘图,这个过程涉及到字符串的分割,正好可以促进自己对C#相关知识的学习.说到分割字符串,我 ...

  7. Struts2学习三----------Action搜索顺序

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2的Action的搜索顺序 http://localhost:8080/path1/path2/student.action 1)判断pa ...

  8. IOS中公布应用程序,进度条一直不走怎么处理

    在IOS中公布应用程序非常是喜闻乐见. 近期1周.我更新了6次版本号.可是时不时的会卡住,进度条不走. 最后总结了几个原因. 1.在公布前你要确认自己的证书是否配置正确 2.DNS域名server有没 ...

  9. ubuntu下matlab的无界面启动---命令行操作

    命令行下运行 Matlab 及 函数 首先参考命令行下matlab的运行参数的定义与作用:http://www.cnblogs.com/beanocean/p/3677404.html 创建示例程序: ...

  10. VS中单元测试用法

    using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTestProject1 { [Test ...