BOJ 문제풀이

백준 10867번 c++ 풀이

koreasunoo 2021. 9. 19. 22:42

안녕하세요 오늘은 중복 제외 정렬 문제를 풀어보겠습니다.

 

전략:

1. 먼저 정렬을 한 후, 출력할 때 전과 다른지 비교하여 같으면 출력하지 않고 같지 않으면 출력하고 x에 그 수를 대입한다.

 

코드:

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin>>N;
	vector<int> v(N);
	for(int i =0; i<N; ++i){
		cin>>v[i];
	}
	sort(v.begin(), v.end());
	int x= -1001;
	for(int i= 0; i<N; ++i){
		if(x!=v[i]){
			cout<<v[i]<<" ";
			x=v[i];
		}
	}
	cout<<"\n";
}

'BOJ 문제풀이' 카테고리의 다른 글

백준 2193번 c++ 풀이  (0) 2021.10.10
백준 2436 c++ 풀이  (0) 2021.10.10
백준 1026번 c++ 풀이  (0) 2021.09.19
백준 1182번 c++ 풀이  (0) 2021.09.19
백준 9461 c++ 풀이  (0) 2021.08.31