Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> a(n);
- iota(a.begin(), a.end(), 1);
- cout << "Full list: " << '\n';
- for (auto& e : a) {
- cout << e << " ";
- }
- cout << '\n' << "Starting from middle: " << '\n';
- for(int i = 0; (n & 1 ? i <= n / 2 : i < n / 2); i++) {
- if (n & 1 && i == 0) {
- //cout << n / 2 - i << '\n';
- continue;
- } else {
- //cout << n / 2 - i << " " << n / 2 + i << '\n';
- int from = n / 2 - i;
- int to = n / 2 + i;
- if (n % 2 == 0) {
- from -= 1;
- }
- cout << a[from] << " " << a[to] << '\n';
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment