first 7 Introductory problems
This commit is contained in:
30
CSES - CSES Problem Set/Permutations.cpp
Normal file
30
CSES - CSES Problem Set/Permutations.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Permutations
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
if (n == 2 || n == 3) {
|
||||
cout << "NO SOLUTION" << endl;
|
||||
return 0;
|
||||
}
|
||||
if (n & 1) {
|
||||
for (int i = n; i >= 1; i -= 2) {
|
||||
cout << i << " ";
|
||||
}
|
||||
for (int i = n-1; i > 1; i -= 2) {
|
||||
cout << i << " ";
|
||||
}
|
||||
} else {
|
||||
for (int i = n - 1; i >= 1; i -= 2) {
|
||||
cout << i << " ";
|
||||
}
|
||||
for (int i = n; i > 1; i -= 2) {
|
||||
cout << i << " ";
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user