题解 | #特殊排序#

特殊排序

https://www.nowcoder.com/practice/57f0f528bff149be9580af66f6292430

#include<vector>
#include<string>
#include<iostream>
#include<tuple>
#include<algorithm>

using namespace std;

int main() {
	int N;
	
	vector<int> vec;
	cin >> N;

	while (N--)
	{
		int x; cin >> x;
		vec.push_back(x);
	}
	auto max_x = max_element(vec.begin(), vec.end());
	cout << *max_x << endl;
	vec.erase(max_x);
	sort(vec.begin(), vec.end());
	
	if (vec.empty())
	{
		cout << -1;
	}else{
		for (auto it = vec.begin(); it != vec.end(); it++) {
			cout << *it << " ";
		}
	}
	

	
}

关键是学会用:

  1. max_element
  2. vec.erase
全部评论

相关推荐

头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务