Day5--算法学习

#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;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值