当前位置:网站首页>Pat class a 1028 list sorting
Pat class a 1028 list sorting
2022-07-03 07:42:00 【IX. is it a non random title】
Be careful vector sort Use
#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;
}边栏推荐
- PgSQL converts string to double type (to_number())
- [coppeliasim4.3] C calls UR5 in the remoteapi control scenario
- Go language foundation ----- 01 ----- go language features
- Go language foundation ------ 14 ------ gotest
- PAT甲级 1031 Hello World for U
- Lucene introduces NFA
- 华为S5700交换机初始化和配置telnet,ssh用户方法
- Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico
- [set theory] order relation (partial order relation | partial order set | example of partial order set)
- Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake
猜你喜欢

【踩坑系列】mysql 修改root密码失败

Partage de l'expérience du projet: mise en œuvre d'un pass optimisé pour la fusion IR de la couche mindstore

Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)

Lucene introduces NFA

Go language foundation ----- 09 ----- exception handling (error, panic, recover)

Epoll related references

密西根大学张阳教授受聘中国上海交通大学客座教授(图)

Usage of requests module

技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估

技术干货|利用昇思MindSpore复现ICCV2021 Best Paper Swin Transformer
随机推荐
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
EtherCAT state machine transition (ESM)
Go language foundation ----- 02 ----- basic data types and operators
Industrial resilience
GoLang之结构体
OSPF protocol summary
Mail sending of vertx
UA camouflage, get and post in requests carry parameters to obtain JSON format content
The babbage industrial policy forum
C2-关于VCF文件合并的几种方法
Read config configuration file of vertx
PAT甲级 1028 List Sorting
华为交换机Console密码重置、设备初始化、默认密码
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
PgSQL converts string to double type (to_number())
Traversal in Lucene
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
在浏览器输入url后执行什么
https://github.com/ZouJiu1/PAT