sort函数(长度升降)

#include <bits/stdc++.h>
using namespace std;
bool www(string &a,string &b){
    return a.size()<b.size();
}
int main(){
    vector <string> s={"asdasda","ggaggagaqq3","agagwfWT"};
    sort(s.begin(),s.end(),www);
    cout<<"长度升序";
    for(string i:s){
        cout<<i<<" ";
    }
    sort(s.rbegin(),s.rend(),www);
    cout<<"长度降序";
    for(auto i:s){
        cout<<i<<" ";
    }
    return 0; 
}
posted @ 2025-07-26 15:18  爱吃泡面的皮卡  阅读(10)  评论(0)    收藏  举报