Advertisement
filashkov

Untitled

Nov 15th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. struct GENIUS_ARRAY
  8. {
  9.     int VALUE;
  10.     struct GENIUS_ARRAY* NEXT;
  11.     struct GENIUS_ARRAY* PREVIOUS;
  12. };
  13.  
  14. int main(void)
  15. {
  16.     int n;
  17.     scanf("%d", &n);
  18.     struct GENIUS_ARRAY* a = (struct GENIUS_ARRAY *)malloc(sizeof(struct GENIUS_ARRAY) * n);
  19.     a->VALUE = 1;
  20.     a->NEXT = a + 1;
  21.     a->PREVIOUS = NULL;
  22.     for (int i = 1; i < n - 1; i++)
  23.     {
  24.         a->VALUE = i + 1;
  25.         a->NEXT = a + 1;
  26.         a->PREVIOUS = a - 1;
  27.     }
  28.     a->VALUE = n;
  29.     a->NEXT = NULL;
  30.     a->PREVIOUS = a - 1;
  31.     int m;
  32.     scanf("%d", &m);
  33.     for (int i = 0; i < m; i++)
  34.     {
  35.         int b, c;
  36.         scanf("%d%d", &b, &c);
  37.         b--;
  38.         c--;
  39.         a[0].PREVIOUS = a + c;
  40.         a[b].PREVIOUS->NEXT = a[c].NEXT;
  41.         a[c + 1].PREVIOUS = a[b].PREVIOUS;
  42.  
  43.         a[b].PREVIOUS = NULL;
  44.     }
  45.     int index = 0;
  46.     for ( ; index < n; index++)
  47.     {
  48.         if ((a + index)->PREVIOUS == NULL)
  49.         {
  50.             break;
  51.         }
  52.     }
  53.     for ( ; ; )
  54.     {
  55.         cout << a[index].VALUE << " ";
  56.         if (a[index].NEXT = NULL)
  57.         {
  58.             break;
  59.         }
  60.     }
  61.     cout << endl;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement