Advertisement
Imran2544

H(IUT IUPC)

Apr 14th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.92 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // - - - - - - Data Types - - - - - - //
  5.  
  6. typedef long long int LLI;
  7. typedef long int LI;
  8. typedef long long LL;
  9.  
  10. // - - - - - - Vectors - - - - - - //
  11. typedef vector<int> VI;
  12. typedef vector<LLI> VLLI;
  13. typedef vector<string> VS;
  14. typedef vector<double> VD;
  15. typedef vector<VI> VVI;
  16.  
  17. #define scanVI(v, n)        for(int i=0; i<n; i++){ int x; cin >> x; v.PB(x); }
  18. #define scanVLLI(v, n)      for(int i=0; i<n; i++){ LLI x; cin >> x; v.PB(x); }
  19. #define scanVS(v, n)        for(int i=0; i<n; i++){ string x; cin >> x; v.PB(x); }
  20. #define scanVD(v, n)        for(int i=0; i<n; i++){ double x; cin >> x; v.PB(x); }
  21.  
  22. // - - - - - - Maps - - - - - - //
  23. typedef map<int, int> MII;
  24. typedef map<int, string> MIS;
  25. typedef map<int, char> MIC;
  26. typedef map<string, int> MSI;
  27. typedef map<char, int> MCI;
  28. typedef map<int, VI> MIVI;
  29.  
  30. // - - - - - - Pairs - - - - - - //
  31. typedef pair<int, int> PII;
  32. typedef pair<string, string> PSS;
  33. typedef pair<char, char> PCC;
  34. typedef pair<int, string> PIS;
  35. typedef pair<int, char> PIC;
  36. typedef pair<string, char> PSC;
  37.  
  38. // - - - - - - Sets - - - - - - //
  39. typedef set<int> SI;
  40. typedef set<LLI> SLLI;
  41. typedef set<string> SS;
  42. typedef set<char> SC;
  43. // - - - - - - - - - - - - - - - - - - //
  44.  
  45. #define PF                  printf
  46. #define SF                  scanf
  47. #define PB                  push_back
  48. #define POP                 pop_back()
  49. #define PP                  prev_permutation
  50. #define NP                  next_permutation
  51. #define MP                  make_pair
  52. #define CLRN(a, b)          memset(a, b, sizeof(a))
  53. #define CLR(a)              memset(a, 0, sizeof(a))
  54. #define ALL(a)              a.begin(), a.end()
  55. #define ALLN(a, n)          (a, a+n)
  56. #define BSRCN(a, n, x)      binary_search(ALLN(a, n), x)
  57. #define BSRC          binary_search
  58. #define MAX                 10000007
  59. #define MIN                 -10000007
  60. #define PI                  acos(-1)
  61. #define BR                  PF("\n")
  62. #define FastIO              ios_base::sync_with_stdio(false)
  63. #define READ()              freopen("input.txt", "r", stdin)
  64. #define WRITE()             freopen("output.txt", "w", stdout)
  65. #define len(a)              a.length()
  66. #define rsort(a)            sort(a.rbegin(), a.rend())
  67. #define pvec(v)             for(auto x: v) cout<<x<<" "
  68.  
  69. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  70. /*----------------------Graph Moves----------------*/
  71. int ROW[]={+1,-1,+0,+0};
  72. int COL[]={+0,+0,+1,-1};
  73.  
  74. int X[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
  75. int Y[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
  76.  
  77. int KX[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
  78. int KY[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
  79. /*------------------------------------------------*/
  80.  
  81. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  82. int LCM(int a, int b) { return a * (b/GCD(a, b)); }
  83. bool CMP(int a, int b) { return a>b; }
  84.  
  85. // - - - - - - - - - - - - - - - - - - - - - - - - - - - END - - - - - - - - - - - - - - - - - - - - - - - - - //
  86.  
  87. #define eps 1e-2
  88. map<char, vector<string> > m;
  89.  
  90. int main()
  91. {
  92.     // FastIO;
  93.     #ifndef ONLINE_JUDGE
  94.      clock_t Start=clock();
  95.      freopen("in.txt", "r", stdin);
  96.      freopen("out.txt", "w", stdout);
  97.     #endif
  98.    
  99.     int t;
  100.     cin>>t;
  101.     while (t--) {
  102.         int n, q;
  103.         cin>>n;
  104.         string s;
  105.         while (n--) {
  106.             cin>>s;
  107.             char c=s[0];
  108.             m[c].PB(s);
  109.         }
  110.         for (char i='A'; i<='D'; i++)
  111.             rsort(m[i]);
  112.         char trash;
  113.         cin>>q;
  114.         while (q--) {
  115.             cin>>trash;
  116.             getline(cin, s);
  117.  
  118.             char k=s[0];
  119.             cout << m[k].back() << '\n';
  120.             m[k].pop_back();
  121.         }
  122.     }
  123.  
  124.     #ifndef ONLINE_JUDGE
  125.      printf("\n>>Runtime: %.10fs\n", (double) (clock() - Start) / CLOCKS_PER_SEC);
  126.     #endif
  127.     return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement