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> ...
随机推荐
- java和.net的类比
原文地址在http://www.seguetech.com/blog/2013/06/03/dotnet-vs-java-how-to-pick
- json 帮助工具
import java.lang.reflect.Type; import com.google.gson.Gson; /** * json 帮助工具 */public final class Gso ...
- MVC 项目中又一新方法实现依懒注入 (AutoFac)
详情请查看:http://docs.autofac.org/en/latest/integration/mvc.html#quick-start
- 开始制作国产的 scratch
首先分析下API和数据格式: https://api.scratch.mit.edu/proxy/featured GET 23.235.37.162:443 返回数据与对应栏目: commun ...
- Nginx运行Laravel的配置
修改nginx.conf.修改前记得备份一下,万一改错了还能还原回去. server { listen 80; server_name localhost; set $root_path '/usr/ ...
- 解决在IIS中调用Microsoft Office Excel组件后进程无法正常退出的问题
来源:http://www.cnblogs.com/ahui/archive/2013/03/05/2944441.html 有一个项目用到Excel组件产生报表,本以为这个通用功能是个很简单的cas ...
- SQL 查询时间段内的时间
declare @dt1 as datetime declare @dt2 as datetime set @dt1 = '2008-01-01' set @dt2 = '2009-01-01' ;w ...
- cocos2d-x中使用tinyxml遇到的问题及解决
1.问题: cocos2d-x集成tinyxml后在vs下运行正常,但是在Android下在读取xml文件时发生异常,读取时使用的是LoadFile函数 2. 解决方案: 先把xml文件内容读取到内存 ...
- Tree Cutting
Tree Cutting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) Prob ...
- php moungoDB
moungoDB 语法 SQL查询语句 Mongo查询语句 CREATE TABLE USERS (a Number, b Number) 隐式的创建,或 MongoDB::createCollect ...