rt,和小朋友吵架说我用vector甩他100ms(我们用的OJ只能手动O2,O3)
结果小朋友用数组+快读,不过思路不是很清晰,但是我只领先了97ms……
题目大意是给定 n 和 n 个数,按绝对值排序,如果绝对值相等就先输出原来小的
以 0
作为结束符
有无除了指令集以外打爆他的方法
#include <bits/stdc++.h>
#define JS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
vector<pair<int, int>> v;
bool cmp(pair<int, int> x, pair<int, int> y) {
if (x.first > y.first ) {
return true;
}
if (x.first == y.first && x.second < y.second ) {
return true;
}
return false;
}
int n;
int main() {
JS;
while (cin >> n && n != 0) {
int t;
for (int i = 1; i <= n; i++) {
cin >> t;
v.push_back(make_pair(abs(t), t));
}
sort(v.begin(), v.end(), cmp);
for (auto i : v) {
cout << i.second << " ";
}
cout << '\n', v.clear();
}
return 0;
}
有点颜面扫地……