목록정렬 (3)
안 쓰던 블로그
[정렬과 이분탐색] 1920 수 찾기 #include #include #include #include using namespace std; vector v; int n; int find(int num) { int s = 0, e = n - 1; while (s > n; for (int i = 0; i > a; v.push_back(a); } //int m; cin >> m; //for (int i = 0; i > a; //auto it = find(v.begin(), v.end(), a); //if (it == v.end()) cout a; cout n; for(int i=0;i> x; a[x]++; //인덱스 증가..

A=60, B=87, C=72, D=96, E=84 라는 값을 정렬하고자 한다 정보를 두 개의 array에 이렇게 담았다 두 array는 지금 암묵적으로 연결되어 있는 상태이다 score를 기준으로 정렬을 했을 때 name도 같이 정려되게 하려면 어떻게 해야 할까? Numpy의 argsort()를 이용하면 쉽게 할 수 있다 argsort()는 원본 행렬 정렬 시 정렬된 행렬의 원래 인덱스를 필요로 할 때 사용한다 이것을 이용하면 정렬 행렬의 원본 행렬 인덱스를 ndarray 형으로 반환해 준다 예를 들어보자 원본 행렬 인덱스가 0 1 2 3 원본 행렬 A가 3, 1, 9, 5 일 때 정렬 행렬은 1, 3, 5, 9 정렬된 행렬의 원본 행렬 인덱스는 1, 0, 3, 2 이다 argsort()는 1, 0, ..
문제 풀 때마다 맨날 헷갈려서 정리했음 1. 일반 배열 내림차순 정렬 #include #include using namespace std; int n, a[10]; bool compare2(const int&x, const int&y) { return x > y; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n, compare2); for (int i = 0; i < n; i++) { printf("%d\n", a[i]); } } 2. vector 오름차순 정렬 #include #include #include using namespace std; int n; vector a(5)..