Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- //#define FILE 10
- #define int int64_t
- using namespace std;
- using namespace __gnu_pbds;
- template<typename T>
- using orset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- template<typename T, typename K>
- using ormap = tree <T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
- const int N = 1e5;
- int sqr(int x)
- {
- return x * x;
- }
- void solve()
- {
- int n;
- cin >> n;
- vector <pair <string, string>> ans;
- map <char, string> now;
- while (n--)
- {
- string s;
- cin >> s;
- if (now [s.back()] != "")
- {
- ans.push_back({now [s.back()], s});
- now.erase(s.back());
- }
- else
- now [s.back()] = s;
- }
- cout << ans.size() << "\n";
- for (auto i: ans)
- cout << i.first << " " << i.second << "\n";
- }
- int32_t main(int32_t argc, char* argv[]) {
- ios::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- #ifdef FILE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t = 1;
- //cin >> t;
- while (t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment