PAT甲题题解-1028. List Sorting (25)-水排序
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <queue>
using namespace std; /*
水排序
*/
const int maxn=+;
int n,c; struct Stu{
int ID;
char name[];
int grade;
}stu[maxn]; bool cmpID(Stu s1,Stu s2){
return s1.ID<s2.ID;
}
bool cmpName(Stu s1,Stu s2){
if(strcmp(s1.name,s2.name)==)
return s1.ID<s2.ID;
else if(strcmp(s1.name,s2.name)<)
return true;
else
return false;
} bool cmpGrade(Stu s1,Stu s2){
if(s1.grade==s2.grade){
return s1.ID<s2.ID;
}
else{
return s1.grade<s2.grade;
} }
int main()
{
scanf("%d %d",&n,&c);
for(int i=;i<n;i++){
scanf("%d %s %d",&stu[i].ID,stu[i].name,&stu[i].grade);
}
if(c==)
sort(stu,stu+n,cmpID);
else if(c==)
sort(stu,stu+n,cmpName);
else
sort(stu,stu+n,cmpGrade);
for(int i=;i<n;i++){
printf("%06d %s %d\n",stu[i].ID,stu[i].name,stu[i].grade);
}
return ;
}
PAT甲题题解-1028. List Sorting (25)-水排序的更多相关文章
- PAT甲题题解-1048. Find Coins (25)-水
给n,m以及n个硬币 问,是否存在两个硬币面值v1+v2=m 因为面值不会超过500,所以实际上最多500个不同的硬币而已 #include <iostream> #include < ...
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲题题解-1051. Pop Sequence (25)-堆栈
将1~n压入最多为m元素的栈 给出k个出栈序列,问你是否能够实现. 能输出YES 否则NO 模拟一遍即可,水题. #include <iostream> #include <cstd ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- PAT甲题题解-1101. Quick Sort (25)-大水题
快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...
- PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...
- PAT甲题题解-1130. Infix Expression (25)-中序遍历
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲题题解-1129. Recommendation System (25)-排序
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲题题解-1016. Phone Bills (25)-模拟、排序
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- 读高性能JavaScript编程 第二章 让我知道了代码为什么要这样写
代码为什么要这样写? function initUI(){ var doc = document, bd = doc.body, links = doc.getElementsByTagName_r( ...
- 使用C#获取Windows Phone手机的各种数据(转)
转自:http://www.sum16.com/desinger/use-c-sharp-get-windows-phone-information.html 使用C#获取Windows Phone手 ...
- cJSON 使用详解
由于c语言中,没有直接的字典,字符串数组等数据结构,所以要借助结构体定义,处理json.如果有对应的数据结构就方便一些, 如python中用json.loads(json)就把json字符串转变为内建 ...
- 【2017下集美大学软工1412班_助教博客】团队作业3——需求改进&系统设计团队成绩公示
作业要求 团队作业3--需求改进&系统设计 团队评分结果 Total QH BZ GJ MS SXX WBS SJ JG SJK JH NR CS PHILOSOPHER 需求改进&系 ...
- [Python2]介绍关于Uiautomator的watcher使用场景及使用方法
[官方的介绍]: Watcher You can register watcher to perform some actions when a selector can not find a mat ...
- Oracle rdbms Brush password
Restore database user history account password 1. 用户状态 select * from user_astatus_map; select * from ...
- vagrant特性——基于docker开发环境(docker和vagrant的结合)-1-基本使用
Docker vagrant提供了使用Docker作为provider(其他的provider有virtualBox.VMware\hyper-V等)的开箱即用支持.这允许你的开发环境由Docker容 ...
- MP实战系列(十四)之分页使用
MyBatis Plus的分页,有插件式的,也有其自带了,插件需要配置,说麻烦也不是特别麻烦,不过觉得现有的MyBatis Plus足以解决,就懒得配置插件了. MyBatis Plus的资料不算是太 ...
- OpenCV——边缘检测(sobel算子、Laplacian算子、scharr滤波器)
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- centos 7 配置iptables(转) + iptabes规则理解
一.防火墙配置 1.检测并关闭firewall 1 2 3 4 5 systemctl status firewalld.service #检测是否开启了firewall systemctl st ...