Programming_prob/BaekJoon
[백준] 2750, 2751, 10989번 / 수 정렬하기1, 2, 3
YongArtist
2020. 6. 29. 14:13
sort 알고리즘을 공부하면서 알게된 내용을 활용해서 풀었다.
[2750, 2751번] 수 정렬하기1, 2
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n = 0;
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<pair<int, int>> v(n);
for (int i=0; i<n; i++){
cin >> v[i].first;
v[i].second = i;
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++)
cout << v[i].first << '\n';
return 0;
}
[10989번] 수 정렬하기3
#include <iostream>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int arr[10001]={0,};
int n = 0;
cin >> n;
for(int i=0; i<n; i++){
int tmp = 0;
cin >> tmp;
arr[tmp]++;
}
for(int i = 1 ; i <= 10000; i++)
for (int j = 0; j < arr[i]; j++)
cout << i << "\n";
return 0;
}
//배열의 index를 활용하여 정렬
vector, pair를 모를 경우 여기클릭