문제 링크입니다: https://www.acmicpc.net/problem/10867
10867번: 중복 빼고 정렬하기
첫째 줄에 수의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째에는 숫자가 주어진다. 이 수는 절댓값이 1,000보다 작거나 같은 정수이다.
www.acmicpc.net
절댓값이 1000 이하인 숫자들이 등장하므로 음수를 고려하여 각 숫자 + 1000을 visited 배열에 표시해주면 되는 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
const int MAX = 1000 * 2 + 1; | |
bool visited[MAX]; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
vector<int> v; | |
for (int i = 0; i < N; i++) | |
{ | |
int num; | |
cin >> num; | |
if (!visited[num + 1000]) | |
{ | |
v.push_back(num); | |
visited[num + 1000] = true; | |
} | |
} | |
sort(v.begin(), v.end()); | |
for (int i = 0; i < v.size(); i++) | |
{ | |
cout << v[i] << " "; | |
} | |
cout << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 15657번 N과 M (8) (0) | 2019.10.22 |
---|---|
백준 15656번 N과 M (7) (2) | 2019.10.22 |
백준 16120번 PPAP (0) | 2019.10.22 |
백준 2012번 등수 매기기 (0) | 2019.10.22 |
백준 2457번 공주님의 정원 (0) | 2019.10.22 |