是什么奇葩的测点,最简单的方法AC了,难的TLE,橙题很容易让人误解
AC代码
#include <bits/stdc++.h>
using namespace std;
long long n, a[100010];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a,a+n);
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}
60代码
#include <bits/stdc++.h>
using namespace std;
long long n, a[100010];
void bubblesort() {
for (int i = 0; i < n; i++) {
bool s = 1;
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
s = 0;
}
}
if (s) {
break;
}
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bubblesort();
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}