题解 | 最长&最短文本

#include <bits/stdc++.h>
#include <vector>
using namespace std;
struct stri{
    int lenth;
    string s;
    stri(string s):s(s),lenth(s.size()){};
    bool operator<(stri b){
        return lenth<b.lenth;
    }
};

int main(){
    string s;
    vector<stri>a;
    while(getline(cin,s)){
        a.push_back(stri(s));
    }
    sort(a.begin(),a.end());
    stri x=a[0],y=a[a.size()-1];
    int i=0,j=a.size()-1;
    while(a[i].lenth==x.lenth){
        cout<<a[i++].s<<endl;
    }
    stack<stri>st;
    while(a[j].lenth==y.lenth){
        st.push(a[j--]);
    }
    while(!st.empty()){
        cout<<st.top().s<<endl;
        st.pop();
    }
}

逆天题目,你是句子你直说啊

全部评论

相关推荐

27届学院本誓死冲击...:自我评价和校园经历全删了,荣誉经历只留奖学金,项目也全得换都不如外卖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务