Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
  2. #include <iomanip>
  3. #include <stdio.h>
  4. #include <map>
  5. #include <ctime>
  6. #include <queue>
  7. #include <iostream>
  8. #include <cmath>
  9. #include <vector>
  10. #include <string>
  11. #include <algorithm>
  12. #include <fstream>
  13. #include <set>
  14. #include <list>
  15. #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  16. #define ss second
  17. #define ff first
  18. #define ll long long
  19. #define mp make_pair
  20. #define endl "\n"
  21. #define pb push_back
  22. #define ld long double
  23. #define M_PI 3.14159265358979323846
  24. const ld EPS = 0.0001;
  25. const ll INF = 1000000007;
  26. using namespace std;
  27.  
  28. int get_int(string s)
  29. {
  30. int coef = 1;
  31. int res = 0;
  32. for (int i = s.size() - 1; i >= 0; i--)
  33. {
  34. res += ((int)(s[i] - '0'))*coef;
  35. coef *= 10;
  36. }
  37. return res;
  38. }
  39.  
  40. deque<int> get_deque(string s)
  41. {
  42. string n="";
  43. deque<int> ans;
  44. for (int i = 0; i < s.size(); i++)
  45. {
  46. if (s[i] == ' ')
  47. {
  48. ans.pb(get_int(n)-1);
  49. n = "";
  50. }
  51. else
  52. n += s[i];
  53. }
  54. if (n!="")
  55. ans.pb(get_int(n)-1);
  56. n = "";
  57. return ans;
  58. }
  59.  
  60. int main()
  61. {
  62. int n;
  63. cin >> n;
  64. string c;
  65. getline(std::cin, c);
  66. vector<deque<int> > a(n);
  67. int k = 0;
  68. for (int i = 0; i < n; i++)
  69. {
  70. string s;
  71. getline(std::cin, s);
  72. a[i]=get_deque(s);
  73. k += a[i].size();
  74. }
  75. //k /= 2;
  76. vector<deque<int> > b = a;
  77. /*for (int i = 0; i < n; i++)
  78. {
  79. for (int j = 0; j < b[i].size(); j++)
  80. cout << b[i][j]<<' ';
  81. cout << endl;
  82. }*/
  83. for (int h = 0; h < k; h++)
  84. {
  85. for (int i = 0; i < n; i++)
  86. {
  87. if (a[i].size()!=0)
  88. {
  89. if (a[a[i].front()].size()!=0)
  90. {
  91. //cout << i << ' ' << a[a[i].front()].front() << endl;
  92. if (i == a[a[i].front()].front())
  93. {
  94. cout << min(a[i].front(), a[a[i].front()].front()) + 1 << ' ' << max(a[i].front(), a[a[i].front()].front()) + 1 << endl;
  95. a[a[i].front()].pop_front();
  96. a[i].pop_front();
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement