文章

6

粉丝

43

获赞

41

访问

4.4k

头像
简单排序 题解:
P1929 湘潭大学2023年机试题
发布于2024年3月26日 19:16
阅读数 479

简单sort

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		vector<string>ans(n);
		for (int i = 0;i < n;i++) {
			cin >> ans[i];
		}
		sort(ans.begin(), ans.end(), [&](string& a, string& b) {
			return a.size() < b.size();
		});
		for (auto& s : ans) {
			cout << s << endl;
		}
	}

	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发