题解 | 【模板】排序

【模板】排序

https://www.nowcoder.com/practice/40bf74658879460bbf5f1bfe772e8580

#include<bits/stdc++.h>//万能头文件
using namespace std;
const int N=2e5+5;
int a[N];
void solve()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);//c++里的库函数--包含在头文件--<algorithm>
    //使用前需要--#include<algorithm>
    //--默认小于号(递增排序),可自定义比较函数
    //[起始地址,结束地址的下一位,比较函数) -->左闭右开 [1,n+1)
	for(int i=1;i<=n;i++){
		cout<<a[i]<<' ';
	}
}
int main()
{
	ios::sync_with_stdio(false);//取消同步流,加快输入和输出
	cin.tie(nullptr);
	int t=1;
	while(t--){
		solve();
	}
	return 0;
 } 

全部评论

相关推荐

xtu大迫杰:偶遇校友,祝校友offer打牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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