文章

94

粉丝

0

获赞

572

访问

17.6k

头像
字符串排序3 题解:c++
P1261 北京大学机试题
发布于2026年2月10日 14:48
阅读数 260

#include <bits/stdc++.h>
using namespace std;

bool cmp(string a,string b){
    return a.size() < b.size();
}

int main(){

    int n;
    while(cin >> n){
        cin.ignore();
        vector<string> str;
        while(n--){
            string temp;
            getline(cin,temp);
            if(temp == "stop") break;
            else str.push_back(temp);
        }
        sort(str.begin(),str.end(),cmp);
        for(string i : str){
            cout << i << endl;
        }
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发