文章

34

粉丝

0

获赞

6

访问

1.1k

头像
字符串排序3 题解:
P1261 北京大学机试题
发布于2025年8月6日 17:58
阅读数 28

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

int main(){

	int n;
	while(cin >> n){
		getchar(); // 消除回车影响
		vector<string> v;
		while(n --){
			string s; 
			getline(cin, s);
			if(s != "stop") v.push_back(s);
			else break;
		}
		
		sort(v.begin(), v.end(), [](string a, string b){
			return a.length() < b.length();
		});
		
		for(string &s : v) cout << s << '\n';
	}
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发