Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2017 09:26
Show Gist options
  • Save anonymous/5119dbe5c37dcfcebc7f691bf7b68e74 to your computer and use it in GitHub Desktop.
Save anonymous/5119dbe5c37dcfcebc7f691bf7b68e74 to your computer and use it in GitHub Desktop.
IdlePortlyRobberfly created by anonymous - https://repl.it/repls/IdlePortlyRobberfly
#include <iostream>
using namespace std;
void swap(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}
void reverse(int *m, int n1, int n2) {
int tn1 = n1, tn2 = n2;
for (int i = 0; i < (n1 - n2) / 2; ++i) {
swap(m[tn1], m[tn2]);
tn1--;
tn2++;
}
}
int main() {
int n, a, b, c, d;
cin >> n >> b >> a >> d >> c;
a--; b--; c--; d--; // sorry for this... but I think that it's more beautiful, than filling 4 strings...
int *mas = new int[n];
for (int i = 0; i < n; ++i) {
mas[i] = i + 1;
}
reverse(mas, a, b);
reverse(mas, c, d);
for (int i = 0; i < n; ++i) {
cout << mas[i] << ' ';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment