PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接
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) 【结构体排序】的更多相关文章
- 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 ...
 - 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 ...
 - PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】
		
题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...
 - PAT 甲级 1080 Graduate Admission (30 分)  (简单,结构体排序模拟)
		
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
 - HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
		
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
 - 第m大的身份证号码(局部排序代全局、结构体排序)
		
第m大的身份证号码(点击) 时间限制: 1 Sec 内存限制: 128 MB ...
 - 转载 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法
		
转载自:http://www.cnblogs.com/cj695/p/3863142.html sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在 ...
 - 【转】 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法
		
sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能 ...
 
随机推荐
- span设置padding无效
			
<span style="display:inline-block;padding-top:10px">测试<span> 给span加属性 display: ...
 - 2017.2.20 activiti实战--第一章--认识Activiti
			
学习资料:<Activiti实战> 第一章 认识Activiti 内容概览:讲解activiti的特点.接口概览.架构等基本信息. 1.3 Activiti的特点 1.使用mybatis ...
 - 手机APP脚本录制(LoadRunner 12)
			
最近因项目需要,研究了下手机APP脚本录制方法,有需要的童鞋可参考使用! 方法1: 在手机网络中设置网络代理,使用LR12选择Mobile Application – HTTP/HTML协议中代理录制 ...
 - angular - 启用form组件
			
1.导入form组件 2.导出form组件 3.使用form组件
 - merge-sorted-array——合并两个有序数组
			
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...
 - hdu5417(BC)
			
题目链接:点这儿 Victor and Machine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K ( ...
 - 关于  html  中  table  表格  tr,td  的高度和宽度
			
http://wenku.baidu.com/link?url=76BZcBS3YyA1QJwE7pCPJKERPex4uSQEQ1LI5ZkwTCtunw2cBTaLI8E71dxUhFW0CH4h ...
 - 点击出现黑色背景的解决:-webkit-tap-highlight-color:rgba(0,0,0,0)
			
在手机上(iphone)点击按钮的时候,屏幕总会闪动一下,这让页面看起来很不友好也不流畅.解决方案加了一句css就解决了: -webkit-tap-highlight-color:rgba(0,0,0 ...
 - 【7.1.1】ELK集群搭建 之 ES集群
			
写在前边 昨天晚上就已经完成这篇博客了,就是在测试这块是否正常跑起来,晚上没搞完,上班前把电脑关机带着,结果没保存!基本上昨天写的东西都丢了,好在博客园的图片url还在. 为了让大家都轻松些,我轻松写 ...
 - 三、Silverlight中使用MVVM(三)——进阶
			
这篇主要引申出Command结合MVVM模式在应用程序中的使用 我们要做出的效果是这样的 就是提供了一个简单的查询功能将结果绑定到DataGrid中,在前面的基础上,这个部分相对比较容易实现了 我们在 ...