跳到正文

题解

排序算法

songyihao约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年11月4日
收录
2026年11月6日
更新
2026年11月6日
篇幅
约 1 分钟
获赞
1
题目
P1177

版本

  1. v1当前

不一样的做法

C++
#include<bits/stdc++.h>
using namespace std;
int n;
set<int> a;
map<int,int> t;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		a.insert(x);
		t[x]++;
	}
	for(int p:a)
		for(int i=0;i<t[p];i++)
			cout<<p<<' ';
	return 0;
}

以上代码排序时间复杂度是O(n),空间复杂度也是O(n),可以实现排序。

原文