-
-
Save AmazingRoovy/0841f0bb83dfcac0d3c6b35316b9f516 to your computer and use it in GitHub Desktop.
IdlePortlyRobberfly created by anonymous - https://repl.it/repls/IdlePortlyRobberfly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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