文章

84

粉丝

2

获赞

609

访问

75.3k

头像
字符串排序3 题解:
P1261 北京大学机试题
发布于 2026年2月
阅读数 717

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

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

int main() {
	
	int n;
	while (cin >> n) {
	    vector<string> v;
		for (int i = 0; i <= n; i ++ ) {
			string s;
			getline(cin, s);

			if (s == "stop") break;
			if (s != "") v.push_back(s);
		}
		sort(v.begin(), v.end(), cmp);
		for (auto x : v)
		    cout << x << endl;
	}
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发