Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7. int n,x,y, s=0;
  8. int c,k=0;
  9. cin >> n;
  10. int a[100][2] = {0};
  11. for (int i=1; i<2*n; i+=2)
  12. {
  13. cout <<i<<" "<<i+1<<endl;
  14. if (!(cin >> x))
  15. {
  16. s+=1;
  17. cin.clear();
  18. cin.ignore(10, '\n');
  19. }
  20. else
  21. {
  22. if (x == -1) {return 0;}
  23. cin >> y;
  24. if (a[x][0] == 0) a[x][0] = i;
  25. else a[x][1] = i;
  26. if (a[y][0] == 0) a[y][0] = i+1;
  27. else a[y][1] = i+1;
  28. }
  29. if (i == 2*n - 3 && s == 0) goto here1;
  30. }
  31. goto here2;
  32. here1:
  33. for (int i=1; i<=n-s; i++)
  34. {
  35. if (a[i][0] != 0 && a[i][1] == 0) {a[i][1] = 2*n-k; k++;}
  36. }
  37. here2:
  38. for (int i=1; i<=n-s; i++)
  39. {
  40. if (a[i][0] != 0)
  41. {cout << a[i][0] <<" " << a[i][1]<<endl;}
  42. if (!(cin >> c))
  43. {
  44. cin.clear();
  45. cin.ignore(10, '\n');
  46. }
  47. else return 0;
  48. }
  49. cout << -1;
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement