文章

79

粉丝

0

获赞

502

访问

19.6k

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

#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;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发