사전순~
1015번 - 수열 정렬
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef struct {
int value, index, rank;
} node;
bool cmpvalue(node a, node b) {
if (a.value!=b.value) return a.value < b.value;
return a.index<b.index;
}
bool cmpindex(node a, node b) {
return a.index < b.index;
}
int main() {
int n, a;
node nodelist[60];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
nodelist[i].value = a;
nodelist[i].index = i;
}
sort(nodelist, nodelist + n, cmpvalue);
for (int i = 0; i < n; i++) {
nodelist[i].rank = i;
}
sort(nodelist, nodelist + n, cmpindex);
for (int i = 0; i < n; i++) {
cout << nodelist[i].rank;
if (i != n - 1) cout << " ";
}
}
댓글을 작성하려면 로그인해야 합니다.
woo960131 7년 전
중복되는 원소에 대한 처리도 되어 있는 것 같은데 틀렸다고 하네요 ㅠㅠ
제가 놓치고 있는 부분이 뭘까요