ProgMe

Untitled

Jun 7th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. //#define FILE 10
  6. #define int int64_t
  7.  
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10.  
  11. template<typename T>
  12. using orset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  13. template<typename T, typename K>
  14. using ormap = tree <T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  15. mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
  16.  
  17. const int N = 1e5;
  18.  
  19. int sqr(int x)
  20. {
  21. return x * x;
  22. }
  23.  
  24. void solve()
  25. {
  26. int n;
  27. cin >> n;
  28. vector <pair <string, string>> ans;
  29. map <char, string> now;
  30. while (n--)
  31. {
  32. string s;
  33. cin >> s;
  34. if (now [s.back()] != "")
  35. {
  36. ans.push_back({now [s.back()], s});
  37. now.erase(s.back());
  38. }
  39. else
  40. now [s.back()] = s;
  41. }
  42. cout << ans.size() << "\n";
  43. for (auto i: ans)
  44. cout << i.first << " " << i.second << "\n";
  45. }
  46.  
  47. int32_t main(int32_t argc, char* argv[]) {
  48. ios::sync_with_stdio(false);
  49. cin.tie(0);cout.tie(0);
  50. #ifdef FILE
  51. freopen("input.txt", "r", stdin);
  52. freopen("output.txt", "w", stdout);
  53. #endif
  54. int t = 1;
  55. //cin >> t;
  56. while (t--)
  57. solve();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment