본문 바로가기
알고리즘 풀이

수 정렬하기 2

by 남생이야 2024. 8. 7.

 

https://www.acmicpc.net/problem/2751

 

이번엔 입력 받을 숫자의 크기가 크기 때문에 버블 정렬 보단 O(NlogN)을 요구하는 정렬을 사용해야 한다. 그 중에서 퀵 정렬을 사용하기로 했다. 구현으로 풀어보려했지만 시간 초과가 나서 C에 내장된 sort 함수를 사용했다. 

 

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

int main()
{
	vector<int> arr;

	int n; 
	cin >> n;


	for (int i = 0; i < n; i++)
	{
		int num;
		cin >> num; 
		arr.push_back(num);
	}

	sort(arr.begin(), arr.end());

	for (int i = 0; i < n; i++)
	{
		cout << arr[i] << "\n";
	}


	return 0;
}

'알고리즘 풀이' 카테고리의 다른 글

좌표 정렬하기  (0) 2024.08.10
수 정렬하기 3  (0) 2024.08.10
커트라인  (0) 2024.08.07
대표값2  (0) 2024.08.07
수 정렬하기  (0) 2024.08.07