#include <iostream>
using namespace std;
void swap(int *arr, bool *table, int a, int b) {
int temp = arr[b];
arr[b] = arr[a];
arr[a] = temp;
table[a] = table[b] = true;
}
int main() {
int len;
cin >> len;
if (len < 3 && len > 50000) {
return 0;
}
int *arr = new int[len];
bool *table = new bool[len];
for (int i = 0; i < len; i++) {
cin >> arr[i];
table[i] = false;
}
for (int i = 0; i < len-1; i++) {
int temp = arr[i];
for (int j = i+1; j < len; j++) {
if (arr[j] == temp - 1 && table[i] == false && table[j] == false) {
swap(arr, table, i, j);
}
}
}
for (int i = 0; i < len; i++) {
cout << arr[i]<< " ";
}
cin >> arr[1];
return 0;
}
'컴퓨터 > 문제 풀기' 카테고리의 다른 글
백준 16955번 오목, 이길 수 있을까? (0) | 2019.05.20 |
---|---|
10799번 쇠막대기 (0) | 2019.05.13 |
2309번 일곱 난쟁이 (0) | 2019.05.13 |
백준 1780번 종이의 개수 (0) | 2019.05.13 |
백준 2688번 줄어들지 않아 (0) | 2019.05.13 |