Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
- #include <iomanip>
- #include <stdio.h>
- #include <map>
- #include <ctime>
- #include <queue>
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <fstream>
- #include <set>
- #include <list>
- #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define ss second
- #define ff first
- #define ll long long
- #define mp make_pair
- #define endl "\n"
- #define pb push_back
- #define ld long double
- #define M_PI 3.14159265358979323846
- const ld EPS = 0.0001;
- const ll INF = 1000000007;
- using namespace std;
- int get_int(string s)
- {
- int coef = 1;
- int res = 0;
- for (int i = s.size() - 1; i >= 0; i--)
- {
- res += ((int)(s[i] - '0'))*coef;
- coef *= 10;
- }
- return res;
- }
- deque<int> get_deque(string s)
- {
- string n="";
- deque<int> ans;
- for (int i = 0; i < s.size(); i++)
- {
- if (s[i] == ' ')
- {
- ans.pb(get_int(n)-1);
- n = "";
- }
- else
- n += s[i];
- }
- if (n!="")
- ans.pb(get_int(n)-1);
- n = "";
- return ans;
- }
- int main()
- {
- int n;
- cin >> n;
- string c;
- getline(std::cin, c);
- vector<deque<int> > a(n);
- int k = 0;
- for (int i = 0; i < n; i++)
- {
- string s;
- getline(std::cin, s);
- a[i]=get_deque(s);
- k += a[i].size();
- }
- //k /= 2;
- vector<deque<int> > b = a;
- /*for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < b[i].size(); j++)
- cout << b[i][j]<<' ';
- cout << endl;
- }*/
- for (int h = 0; h < k; h++)
- {
- for (int i = 0; i < n; i++)
- {
- if (a[i].size()!=0)
- {
- if (a[a[i].front()].size()!=0)
- {
- //cout << i << ' ' << a[a[i].front()].front() << endl;
- if (i == a[a[i].front()].front())
- {
- cout << min(a[i].front(), a[a[i].front()].front()) + 1 << ' ' << max(a[i].front(), a[a[i].front()].front()) + 1 << endl;
- a[a[i].front()].pop_front();
- a[i].pop_front();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement