PAT (Advanced Level) 1028. List Sorting (25)
时间卡的比较死,用string会超时。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; struct X
{
int id;
char name[];
int score;
}s[+];
int n,C; bool cmp1(const X&a,const X&b){return a.id<b.id;}
bool cmp2(const X&a,const X&b)
{
if(strcmp(a.name,b.name)==) return a.id<b.id;
return strcmp(a.name,b.name)<;
}
bool cmp3(const X&a,const X&b)
{
if(a.score==b.score) return a.id<b.id;
return a.score<b.score;
} int main()
{
scanf("%d",&n); scanf("%d",&C);
int tot=;
for(int i=;i<=n;i++)
{
scanf("%d",&s[i].id);
scanf("%s",s[i].name);
scanf("%d",&s[i].score);
}
if(C==) sort(s+,s++n,cmp1);
else if(C==)sort(s+,s++n,cmp2);
else sort(s+,s++n,cmp3);
for(int i=;i<=n;i++)
{
printf("%06d ",s[i].id);
printf("%s ",s[i].name);
printf("%d\n",s[i].score);
}
return ;
}
PAT (Advanced Level) 1028. List Sorting (25)的更多相关文章
- PTA (Advanced Level) 1028 List Sorting
List Sorting Excel can sort records according to any column. Now you are supposed to imitate this fu ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT (Advanced Level) 1059. Prime Factors (25)
素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- PAT (Advanced Level) 1051. Pop Sequence (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- 【转】mysql函数
MySQL函数 MySQL数据库提供了很多函数包括: 数学函数: 字符串函数: 日期和时间函数: 条件判断函数: 系统信息函数: 加密函数: 格式化函数: 一.数学函数 数学函数主要用于处理数字,包括 ...
- Tomcat服务器顶层结构和启动过程【转】
号外:2016 最流行的是哪一种 Java 应用服务器呢? 通过从部署的 1240 个 JVM 中得到的数据,我们能够确定出现了 862 个容器供应商,或者说是占到了运行环境的 70% 左右.这些容器 ...
- 安装mongodb到系统服务
一定要以管理员身份打开命令窗口; d盘 创建一个mongodb文件夹,里面有个data文件夹,data里面有db文件夹和log文件夹 mongodb文件夹里面还有个文件mongod.cfg 内容如下 ...
- Eclipse+EPIC+PadWalker
来源: http://www.cnblogs.com/itech/archive/2010/02/23/1671676.html http://blog.csdn.net/haoyujie/artic ...
- php 数组操作符
1.数组操作符 数组运算符 例子 名称 结果 $a + $b 联合 $a 和 $b 的联合. $a == $b 相等 如果 $a 和 $b 具有相同的键/值对则为 TRUE. $a === $b 全等 ...
- mongodb分片认证
启动configsvr 1. 确保mongdb的configsvr是采用service模式启动的,即从/etc/init.d下的脚本启动的,其用户是mongod. 2. 确保mongod的配置文件完全 ...
- nextSibling,previousSibling,childNodes常见错误
在使用nextSibling与previousSibling时,常出现选不到预计对象的情况 eg: <div class="a">1</div> <d ...
- CSS Day04 css核心基础
1.在HTML中引入CSS的方法 (1)行内式 行内式即在标记的style属性中设定CSS样式,这种方式本质上没有体现出CSS的优势,因此不推荐使用. 例如: <h1 style=“colo ...
- iOS多线程中performSelector
下面两段代码都在主线程中运行,我们在看别人代码时会发现有时会直接调用,有时会利用performSelector调用,今天看到有人在问这个问题,我便做一下总结, [delegate imageDownl ...
- Udp发送
string message = "0302"; byte[] sendbytes = Encoding.ASCII.GetBytes(message); remoteIpep = ...