#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
// struct student{ // score sort1
// int num;
// int score;
// };
// const int MAX = 100;
// student arr[MAX];
// bool Compare(student x,student y){
// if(x.score == y.score){
// return x.num < y.num;
// }else{
// return x.score < y.score;
// }
// }
//score sort2
// const int MAX = 100;
// struct student{
// string name;
// int score;
// int order; //次序
// };
// student arr[MAX];
// bool Compare1(student x,student y){
// if(x.score == y.score){
// return x.order < y.order;
// }else{
// return x.score < y.score;
// }
// }
// bool Compare2(student x,student y){
// if(x.score == y.score){
// return x.order < y.order;
// }else{
// return x.score > y.score;
// }
// }
//奇偶排序
// bool Compare(int x,int y){
// if(x % 2 == 1 && y % 2 ==1){
// return x > y;
// }else if(x % 2 == 0 && y % 2 == 0){
// return x < y;
// }else if(x % 2 == 1 && y % 2 == 0){
// return true;
// }else{
// return false;
// }
// };
//小白鼠排队
int weight[100],r[100];
bool comp(int x,int y){
return weight[x] < weight[y];
};
int main(){
//排序
// int MAX = 100 + 10;
// int arr[MAX];
// int n;
// while(cin >> n){
// for(int i = 0;i < n;i++){
// cin >> arr[i];
// }
// sort(arr,arr + n); //三个参数,第一个参数为所排序数组的起始地址,第二个参数为末地址,
// //第三个参数为排序函数,默认为快排
// for(int i = 0;i < n;i++){
// cout << arr[i] << ' ';
// }
// cout << endl;
// }
//成绩排序1
// int n;
// cin >> n;
// for(int i = 0;i < n;i++){
// cin >> arr[i].num >> arr[i].score;
// }
// sort(arr,arr + n,Compare);
// for(int i = 0;i < n;i++){
// cout << arr[i].num << ' ' << arr[i].score <<endl;
// }
// }
//score sort2
// int n,method;
// while(cin >>n >> method){
// for(int i = 0;i < n;i++){
// cin >> arr[i].name >> arr[i].score;
// arr[i].order = i;
// }
// if(method == 1){
// stable_sort(arr,arr + n,Compare1);//稳定排序用stable_sort
// }else{
// stable_sort(arr,arr + n,Compare2);
// }
// for(int i = 0;i < n;i++){
// cout << arr[i].name << ' ' << arr[i].score << endl;
// }
// }
// https://www.nowcoder.com/practice/57f0f528bff149be9580af66f6292430?tpId=40&tqId=21543&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking
//特殊排序
// const int MAX = 1000 + 10;
// int arr[MAX];
// int n;
// while(cin >> n){
// for(int i = 0;i < n;i++){
// cin >> arr[i];
// }
// sort(arr,arr + n);
// cout << arr[n - 1] << endl;
// if(n == 1){
// cout << -1;
// }else{
// for(int i = 0;i < n -1;i++){
// cout << arr[i] << ' ';
// }
// }
// }
// https://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163?tpId=40&tqId=21398&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking
//整数奇偶排序
// int arr[10];
// while(cin >> arr[0]){
// for(int i = 1;i < 10;i++){
// cin >> arr[i];
// }
// sort(arr,arr + 10,Compare);
// for(int i = 0;i < 10;i++){
// cout << arr[i] << ' ';
// }
// }
// https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b?tpId=61&tqId=29509&tPage=1&ru=/kaoyan/retest/1002&qru=/ta/pku-kaoyan/question-ranking
//小白鼠排队
string color[100];
int n;
cin >> n;
for(int i = 0;i < n;i++){
r[i] = i;
cin >> weight[i] >> color[i];
}
sort(r,r + n,comp);
reverse(r,r + n);
for(int i = 0;i < n;i++){
cout << color[r[i]] <<endl;
}
Day5--算法学习
最新推荐文章于 2024-10-10 22:59:02 发布