AC

1234567890  •  1小时前


include <bits/stdc++.h>

using namespace std; const int N = 1e6; int n, a[N];

void mp() {

for (long long i = 1; i <= n ; i++) {
	long long ith = a[i];
	long long j = i - 1;
	while (j >= 0 && a[j] > ith) {
		a[j + 1] = a[j];
		j--;
	}
	a[j + 1] = ith;
}

}

int main() {

ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (long long i = 1; i <= n; i++) {
	cin >> a[i];
}
mp();
for (long long i = 1; i <= n; i++) {
	cout << a[i] << " ";
}
return 0;

}


评论:

请先登录,才能进行评论