当前位置:网站首页>PAT甲级 1028 List Sorting
PAT甲级 1028 List Sorting
2022-07-03 07:34:00 【九是否非随机的称呼】
注意vector sort的使用
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
typedef struct _student{
string ID;
string name;
int score;
}student;
bool compare1(const student &h, const student &k){
if(h.ID < k.ID) return true;
else return false;
}
bool compare2(const student &h, const student &k){
if(h.name < k.name) return true;
else if(h.name == k.name){
if(h.ID < k.ID) return true;
else return false;
}
else return false;
}
bool compare3(const student &h, const student &k){
if(h.score < k.score) return true;
else if(h.score == k.score){
if(h.ID < k.ID) return true;
else return false;
}
else return false;
}
int main(int argc, char **argv){
int i, j, a, c, m, n;
cin>>m>>n;
vector<student> v;
student stt;
for(i = 0; i < m; i++){
cin>>stt.ID>>stt.name>>stt.score;
v.push_back(stt);
}
if(n==1) sort(v.begin(), v.end(), compare1);
else if(n==2) sort(v.begin(), v.end(), compare2);
else sort(v.begin(), v.end(), compare3);
for(i = 0; i < m; i++)
cout<<v[i].ID<<" "<<v[i].name<<" "<<v[i].score<<endl;
return EXIT_SUCCESS;
}
边栏推荐
- Beginners use Minio
- Comparison of advantages and disadvantages between most complete SQL and NoSQL
- Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
- Web router of vertx
- Vertx multi vertical shared data
- 技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
- Use of other streams
- Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
- Inverted chain disk storage in Lucene (pfordelta)
- 技术干货|AI框架动静态图统一的思考
猜你喜欢
项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
Leetcode 198: house raiding
【MySQL 11】怎么解决MySQL 8.0.18 大小写敏感问题
[mindspire paper presentation] summary of training skills in AAAI long tail problem
截图工具Snipaste
Leetcode 198: 打家劫舍
【MySQL 12】MySQL 8.0.18 重新初始化
Common methods of file class
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
URL programming
随机推荐
Use of file class
Why is data service the direction of the next generation data center?
Visit Google homepage to display this page, which cannot be displayed
New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
哪一刻你才发现青春结束了
技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
Take you through the whole process and comprehensively understand the software accidents that belong to testing
OSI knowledge sorting
VMware network mode - bridge, host only, NAT network
Understanding of class
Circuit, packet and message exchange
TreeMap
I. D3.js hello world
技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验
IPv4 address
Rabbit MQ message sending of vertx
Vertx restful style web router
TCP cumulative acknowledgement and window value update
圖像識別與檢測--筆記
Map interface and method