You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.0 KiB
53 lines
1.0 KiB
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
struct Num {
|
|
int number; //数字
|
|
int index = 0;//原来的索引号
|
|
int paiming = 0; //排名
|
|
};
|
|
|
|
//对比的方法
|
|
/*
|
|
用大于号就是从大到小排序,用小于号就是从小到大排序
|
|
*/
|
|
bool compare(const Num &x, const Num &y) {
|
|
return x.number < y.number;
|
|
}
|
|
|
|
//按索引排序
|
|
bool compareByIndex(const Num &x, const Num &y) {
|
|
return x.index < y.index;
|
|
}
|
|
|
|
int main() {
|
|
int n;
|
|
cin >> n;
|
|
//声明动态数组
|
|
Num *s = new Num[n];
|
|
//输入
|
|
for (int i = 0; i < n; ++i) {
|
|
cin >> s[i].number;
|
|
s[i].index = i + 1;
|
|
}
|
|
//排序
|
|
sort(s, s + n, compare);
|
|
//填充排名
|
|
for (int i = 0; i < n; ++i) {
|
|
s[i].paiming = i + 1;
|
|
}
|
|
|
|
//按原序排序
|
|
sort(s, s + n, compareByIndex);
|
|
//输出
|
|
for (int i = 0; i < n; ++i) {
|
|
cout << s[i].paiming << " ";
|
|
}
|
|
cout << endl;
|
|
|
|
//删除动态数组
|
|
delete[]s;
|
|
return 0;
|
|
}
|