티스토리 뷰
10867번: 중복 빼고 정렬하기
첫째 줄에 수의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째에는 숫자가 주어진다. 이 수는 절댓값이 1,000보다 작거나 같은 정수이다.
www.acmicpc.net
문제풀이
N개의 정수를 오름차순으로 정렬하는 문제다.
이때 같은 정수는 한 번만 출력해야 한다.
벡터를 정렬해서 중복을 제거한 후 출력을 해주면 되는 아주 간단한 문제다!
C++ 코드
This file contains 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; | |
int main() | |
{ | |
ios::sync_with_stdio(false); | |
cin.tie(NULL); | |
cout.tie(NULL); | |
int n; | |
cin >> n; | |
vector<int> a(n); | |
for (int i = 0; i < n; i++) | |
cin >> a[i]; | |
sort(a.begin(), a.end()); | |
a.erase(unique(a.begin(), a.end()), a.end()); | |
for (int i = 0; i < a.size(); i++) { | |
cout << a[i] << ' '; | |
} | |
return 0; | |
} |
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ 1516] 게임 개발 C++ (0) | 2021.07.16 |
---|---|
[BOJ 3020] 개똥벌레 C++ (0) | 2021.07.16 |
[BOJ 1205] 등수 구하기 C++ (0) | 2021.07.15 |
[BOJ 1026] 보물 C++ (0) | 2021.07.15 |
[BOJ 1342] 행운의 문자열 C++ (0) | 2021.07.15 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 자바
- dfs
- Java
- 재귀
- 그래프
- 구현
- 큐
- 정렬
- SW Expert Academy
- Kotlin
- algorithm
- programmers
- 알고리즘
- 문자열
- BFS
- 두 포인터
- 위상 정렬
- 트리
- Two Pointer
- BOJ
- 이분 탐색
- SWEA
- 배열
- C++
- 프로그래머스
- 백준
- 투 포인터
- 브루트포스
- 분할 정복
- 스택
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함