Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.74 KB | None | 0 0
  1. //==================================================================================================
  2. // Name        : FromStoT.cpp
  3. // Author      : lotus.eater086
  4. // Copyright   : If you're reading this then this warning is for you. Every word you read of this
  5. //               useless fine print is another second of your life. Don't you've other things to do?
  6. //               Is your life so empty that you honestly can't think of a better way to spend these
  7. //               moments ? Or are you so impressed with authority that you give respect and
  8. //               credence to all who claim it ? Do you read everything you're supposed to read ? Do
  9. //               you think everything you're supposed to think ? Buy what you're told you should
  10. //               want ? Get out of your apartment . Meet a member of the opposite sex. Stop the
  11. //               excessive shopping and self-improvement . Quit your boring job.
  12. //               Start a fight. Prove you're alive. If you don't claim your humanity you'll become a
  13. //               statistic. You've been warned !
  14.  
  15. // Description :
  16. // Date        : 2019-07-16
  17. // Time        : 01:18:20
  18. // Directory   : c:\Users\Lenovo\cpPractise\deliberatePractise\code_folder
  19. // FilePath    : c:\Users\Lenovo\cpPractise\deliberatePractise\code_folder\FromStoT.cpp
  20. //==================================================================================================
  21.    
  22.  
  23. #include <bits/stdc++.h>
  24. #define LL long long
  25. #define endl "\n"
  26.  
  27. using namespace std ;
  28.    
  29. //
  30. template < typename T >
  31.  
  32. inline T read( T &x )
  33. {
  34.  
  35.     x = 0 ;
  36.  
  37.     int f = 0 ;
  38.  
  39.     char ch = getchar() ;
  40.  
  41.     while( ch < '0' || ch > '9' )  {
  42.  
  43.         f |= ( ch == '-' ) , ch = getchar() ;
  44.  
  45.     }
  46.  
  47.     while( ch >= '0' && ch <= '9' )  {
  48.  
  49.         x = ( x << 1 ) + ( x << 3 ) + ch - '0' , ch = getchar() ;
  50.  
  51.     }
  52.  
  53.     return x = f ? -x:x ;
  54.  
  55. }
  56. //
  57.  
  58. void printQueue( queue<char>q )
  59. {
  60.  
  61.     queue<char>temp = q ;
  62.  
  63.     while( ! temp.empty() )  {
  64.  
  65.         cout << temp.front() ;
  66.  
  67.         temp.pop() ;
  68.  
  69.     }
  70.  
  71.     cout << endl ;
  72.  
  73. }
  74.  
  75. int main( void )
  76.  
  77. {
  78.  
  79.     //ios_base::sync_with_stdio( false ) ;  cin.tie( NULL ) ;  cout.tie( NULL ) ;
  80.  
  81.     #ifndef ONLINE_JUDGE
  82.         freopen( "input.txt" , "r" , stdin ) ;
  83.         freopen( "output.txt" , "w" , stdout ) ;
  84.     #endif
  85.  
  86.     int q ;
  87.  
  88.     cin >> q ;
  89.  
  90.     while( q-- )  {
  91.  
  92.         string s , t , p ;
  93.  
  94.         cin >> s >> t >> p ;
  95.  
  96.         if( s.size() > t.size() )  {
  97.  
  98.             cout << "NO\n" ;
  99.  
  100.             continue ;
  101.  
  102.         }
  103.  
  104.         else if( s.size() == t.size() && s != t )  {
  105.  
  106.             cout << "NO\n" ;  continue ;
  107.  
  108.         }
  109.  
  110.         else if( s == t )  {
  111.  
  112.             cout << "YES\n" ;
  113.  
  114.             continue ;
  115.  
  116.         }
  117.  
  118.         int sa[26] , ta[26] , pa[26] ;
  119.  
  120.         memset( sa , 0 , sizeof( sa ) ) ;
  121.         memset( ta , 0 , sizeof( ta ) )  ;
  122.         memset( pa , 0 , sizeof( pa ) ) ;
  123.  
  124.         for( int i = 0 ; i < s.size() ; i++ )  sa[ s[i] - 'a' ]++ ;
  125.         for( int i = 0 ; i < t.size() ; i++ )  ta[ t[i] - 'a' ]++ ;
  126.         for( int i = 0 ; i < p.size() ; i++ )  pa[ p[i] - 'a' ]++ ;
  127.  
  128.         bool flag = false ;
  129.  
  130.         for( int i = 0 ; i < 26 ; i++ )  {
  131.  
  132.             if( sa[i] > ta[i] )  {
  133.  
  134.                 flag = true ;
  135.  
  136.                 break ;
  137.  
  138.             }
  139.  
  140.         }
  141.  
  142.         if( flag == true )  {
  143.  
  144.             cout << "NO\n" ;  continue ;
  145.  
  146.         }
  147.  
  148.         for( int i = 0 ; i < 26 ; i++ )  {
  149.  
  150.             if( ta[i] > ( sa[i] + pa[i] ) )  {
  151.  
  152.                 flag = true ;
  153.  
  154.                 break ;
  155.  
  156.             }
  157.  
  158.         }
  159.  
  160.         if( flag == true )  {
  161.  
  162.             cout << "NO\n" ;  continue ;
  163.  
  164.         }
  165.  
  166.         queue < char > sq , tq ;
  167.  
  168.         for( int i = 0 ; i < s.size() ; i++ )  {
  169.  
  170.             for( int j = 0 ; j < t.size() ; j++ )  {
  171.  
  172.                 if( s[i] == t[j] && ta[ t[j] - 'a' ] > 0 )  {
  173.  
  174.                     ta[ t[j] - 'a' ]-- ;  
  175.  
  176.                     sq.emplace( s[i] ) ;
  177.  
  178.                     break ;
  179.  
  180.                 }  
  181.  
  182.             }
  183.  
  184.         }
  185.  
  186.         for( int i = 0 ; i < t.size() ; i++ )  {
  187.  
  188.             for( int j = 0 ; j < s.size() ; j++ )  {
  189.  
  190.                 if( t[i] == s[j] && sa[ s[j] - 'a' ] > 0 )  {
  191.  
  192.                     sa[ s[j] - 'a' ]-- ;
  193.  
  194.                     tq.emplace( s[j] ) ;
  195.  
  196.                     break ;
  197.  
  198.                 }
  199.  
  200.             }
  201.  
  202.         }
  203.  
  204.       //  printQueue( sq ) ;
  205.       //  printQueue( tq ) ;
  206.  
  207.  
  208.         while ( !tq.empty() )
  209.         {
  210.            
  211.             if( tq.front() != sq.front() )  {
  212.  
  213.                 flag = true ;
  214.  
  215.                 break ;
  216.  
  217.             }
  218.  
  219.             tq.pop() ;  sq.pop() ;  
  220.  
  221.         }
  222.        
  223.  
  224.        
  225.  
  226.         if( flag == true )  {
  227.  
  228.             cout << "NO\n" ;  continue ;
  229.  
  230.         }
  231.        
  232.         cout << "YES\n" ;
  233.  
  234.  
  235.     }
  236.  
  237.     #ifndef ONLINE_JUDGE
  238.         cout << "\nTime Elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " sec\n" ;
  239.     #endif
  240.  
  241.     return 0 ;
  242.  
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement