PAT 1028. List Sorting
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; class Stu {
public:
char id[];
char name[];
char grade;
}; bool cmp_id(const Stu* a, const Stu* b) {
return strcmp(a->id, b->id) < ;
} bool cmp_name(const Stu* a, const Stu* b) {
int res = strcmp(a->name, b->name);
if (res > ) {
return false;
} else if (res < ) {
return true;
}
return cmp_id(a, b);
} bool cmp_grade(const Stu* a, const Stu* b) {
if (a->grade > b->grade) {
return false;
} else if (a->grade < b->grade) {
return true;
}
return cmp_id(a, b);
} int main() {
int N, C;
scanf("%d%d", &N, &C);
vector<Stu*> stus(N, NULL); for (int i=; i<N; i++) {
Stu* cur = stus[i] = new Stu();
scanf("%s%s%d", cur->id, cur->name, &(cur->grade));
} // TODO: use function ptr array
if (C==) {
sort(stus.begin(), stus.end(), cmp_id);
} else if (C==) {
sort(stus.begin(), stus.end(), cmp_name);
} else {
sort(stus.begin(), stus.end(), cmp_grade);
} for (int i=; i<N; i++) {
printf("%s %s %d\n", stus[i]->id, stus[i]->name, stus[i]->grade);
}
return ;
}
还是快不起来,那么水的题
PAT 1028. List Sorting的更多相关文章
- PAT 1028 List Sorting[排序][一般]
1028 List Sorting (25)(25 分) Excel can sort records according to any column. Now you are supposed to ...
- PAT 1028 List Sorting (25分) 用char[],不要用string
题目 Excel can sort records according to any column. Now you are supposed to imitate this function. In ...
- 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 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- 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 (Advanced Level) 1028. List Sorting (25)
时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...
- PAT甲题题解-1028. List Sorting (25)-水排序
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【PAT甲级】1028 List Sorting (25 分)
题意: 输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数).输出排序后的信 ...
随机推荐
- 模块time, datetime的用法
一. time time库提供了各种操作时间的方法 1. time.asctime([tuple]):将一个时间元组转换成一个可读的24个时间字符串. >>> time.asc ...
- Oracle 中wmsys.wm_concat拼接字符串,结果过长报错解决
备忘:这个函数最大是4000,根据拼接列的长度,通过限制拼接条数来防止拼接字符串过长错误 --这个情况是从子表中读取出具,这里直接把它当做查询字段处理,在子表中有所有数据 select info.id ...
- 傻瓜式学Python3——列表
前言: 好久不见,突然发觉好久没写博客了,最近迷上了 Python 无法自拔,了解了一下,Python 简单易学,尤其是接触过java的人,入门 Python 更是门槛极低,本着学习记录的原则,边学习 ...
- python 入门级教你如何拿到小姐姐微信
第一题: 首先错误的思路,首先找出 707829217/2+1 里面的所有奇数,然后再利用两个for,来判断 import math def func_get_prime(n): return ...
- FPGA基础学习(6) -- 原语
目录 1. IBUF和IBUFDS(IO) 2. IDDR(Input/Output Functions) 3. IBUFG和IBUFGDS(IO) 原语,即primitive.不同的厂商,原语不同: ...
- 【算法笔记】B1045 快速排序
1045 快速排序 (25 分) 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后 ...
- 02-线性结构3 Reversing Linked List (25 分)
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...
- C语言实现数组逆置
#include <stdio.h> #include <assert.h> void swap(int *a ,int *b) { int tmp = *a; *a = *b ...
- JS及Dom示例 | 分级菜单折叠
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 为什么要实现Serializable
工作中我们经常在进行持久化操作和返回数据时都会使用到javabean来统一封装参数,方便操作,一般我们也都会实现Serializable接口,那么问题来了,首先:为什么要进行序列化:其次:每个实体be ...