11870번 좌표 압축
2023. 4. 3. 09:14ㆍBaekJoon
단계별로 풀어보기 - 정렬 - 10단계
https://www.acmicpc.net/problem/18870
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int N,temp;
cin>>N;
vector<int>a,b;
for(int i=0;i<N;i++)
{
cin>>temp;
a.push_back(temp);
b.push_back(temp);
}
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
for(int i:b)
{
int print=lower_bound(a.begin(),a.end(),i)-a.begin();
cout<<print<<" ";
}
return 0;
}
🔊lower_bound()함수는
찾으려는 key 값이나 그보다 큰 숫자의
배열의 최초 위치를 알려준다
'BaekJoon' 카테고리의 다른 글
15650번 N과 M (2) (0) | 2023.04.03 |
---|---|
15649번 N과 M (1) (0) | 2023.04.03 |
10814번 나이순 정렬 (0) | 2023.04.03 |
1181번 단어 정렬 (0) | 2023.04.03 |
11651번 좌표 정렬하기 2 (0) | 2023.04.03 |