Advertisement
Shiam7777777

Untitled

Apr 14th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  4. #define ll long long
  5. #define ld double
  6. #define llu long long unsigned
  7.  
  8. bool comp( string x , string y )
  9. {
  10.     for( int i = 0 ; i < min( x.size() , y.size() ) ; i++ )
  11.     {
  12.         if( x[i] >= 'A' and x[i] <= 'Z' and y[i] >= 'a' and y[i] <= 'z' and y[i] - 'a' < x[i] - 'A' )
  13.             return 1;
  14.         else if( x[i] >= 'A' and x[i] <= 'Z' and y[i] >= 'a' and y[i] <= 'z' )
  15.             return 0;
  16.         else if( y[i] >= 'A' and y[i] <= 'Z' and x[i] >= 'a' and x[i] <= 'z' and x[i] - 'a' < y[i] - 'A' )
  17.             return 0;
  18.         else if( y[i] >= 'A' and y[i] <= 'Z' and x[i] >= 'a' and x[i] <= 'z' )
  19.             return 1;
  20.         else if( y[i] < x[i] )
  21.             return 1;
  22.         else if( x[i] < y[i] )
  23.             return 0;
  24.     }
  25. }
  26.  
  27. void merge(vector < string > &arr, int l, int m, int r)
  28. {
  29.     int i, j, k;
  30.     int n1 = m - l + 1;
  31.     int n2 =  r - m;
  32.  
  33.     string L[n1], R[n2];
  34.  
  35.     for (i = 0; i < n1; i++)
  36.         L[i] = arr[l + i];
  37.     for (j = 0; j < n2; j++)
  38.         R[j] = arr[m + 1+ j];
  39.  
  40.     i = 0;
  41.     j = 0;
  42.     k = l;
  43.     while (i < n1 && j < n2)
  44.     {
  45.         if ( comp( R[j] , L[i] ) )
  46.         {
  47.             arr[k] = L[i];
  48.             i++;
  49.         }
  50.         else
  51.         {
  52.             arr[k] = R[j];
  53.             j++;
  54.         }
  55.         k++;
  56.     }
  57.  
  58.     while (i < n1)
  59.     {
  60.         arr[k] = L[i];
  61.         i++;
  62.         k++;
  63.     }
  64.  
  65.     while (j < n2)
  66.     {
  67.         arr[k] = R[j];
  68.         j++;
  69.         k++;
  70.     }
  71. }
  72.  
  73. void mergeSort(vector < string > &arr, int l, int r)
  74. {
  75.     if (l < r)
  76.     {
  77.         int m = l+(r-l)/2;
  78.  
  79.         mergeSort(arr, l, m);
  80.         mergeSort(arr, m+1, r);
  81.  
  82.         merge(arr, l, m, r);
  83.     }
  84. }
  85.  
  86. int main()
  87. {
  88.     fast;
  89.     int tt;
  90.     cin>>tt;
  91.     for( int i = 1 ; i <= tt ; i++ )
  92.     {
  93.         int n;
  94.         cin>>n;
  95.         vector < string > a;
  96.         vector < string > b;
  97.         vector < string > c;
  98.         vector < string > d;
  99.         while( n-- )
  100.         {
  101.             string s;
  102.             cin>>s;
  103.             if( s[0] == 'A' or s[0] == 'a' )
  104.                 a.push_back( s );
  105.             if( s[0] == 'B' or s[0] == 'b' )
  106.                 b.push_back( s );
  107.             if( s[0] == 'C' or s[0] == 'c' )
  108.                 c.push_back( s );
  109.             if( s[0] == 'D' or s[0] == 'd' )
  110.                 d.push_back( s );
  111.         }
  112. //        sort( a.begin() , a.end() );
  113.         mergeSort( a , 0 , a.size() - 1 );
  114. //        sort( b.begin() , b.end() );
  115.         mergeSort( b , 0 , b.size() - 1 );
  116. //        sort( c.begin() , c.end() );
  117.         mergeSort( c , 0 , c.size() - 1 );
  118. //        sort( d.begin() , d.end() );
  119.         mergeSort( d , 0 , d.size() - 1 );
  120. //        for( int i = 0 ; i < a.size() ; i++ )
  121. //            cout<<a[i]<<endl;
  122. //        for( int i = 0 ; i < b.size() ; i++ )
  123. //            cout<<b[i]<<endl;
  124. //        for( int i = 0 ; i < c.size() ; i++ )
  125. //            cout<<c[i]<<endl;
  126. //        for( int i = 0 ; i < d.size() ; i++ )
  127. //            cout<<d[i]<<endl;
  128.         cin>>n;
  129.         for( int  i = 0 ; i <= n ; i++ )
  130.         {
  131.             string s;
  132. //            getchar();
  133.             getline( cin , s );
  134.             if( !i )
  135.                 continue;
  136. //            cout<<s<<endl;
  137.             if( s[0] == 'A' and a.size() )
  138.             {
  139.                 cout<<a[0]<<endl;
  140.                 a.erase( a.begin() );
  141.             }
  142.             else if( s[0] == 'B' and b.size() )
  143.             {
  144.                 cout<<b[0]<<endl;
  145.                 b.erase( b.begin() );
  146.             }
  147.             else if( s[0] == 'C' and c.size() )
  148.             {
  149.                 cout<<c[0]<<endl;
  150.                 c.erase( c.begin() );
  151.             }
  152.             else if( s[0] == 'D' and d.size() )
  153.             {
  154.                 cout<<d[0]<<endl;
  155.                 d.erase( d.begin() );
  156.             }
  157.             else
  158.                 cout<<"Already Mastered"<<endl;
  159.         }
  160.     }
  161.     return 0;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement