Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==================================================================================================
- // Name : FromStoT.cpp
- // Author : lotus.eater086
- // Copyright : If you're reading this then this warning is for you. Every word you read of this
- // useless fine print is another second of your life. Don't you've other things to do?
- // Is your life so empty that you honestly can't think of a better way to spend these
- // moments ? Or are you so impressed with authority that you give respect and
- // credence to all who claim it ? Do you read everything you're supposed to read ? Do
- // you think everything you're supposed to think ? Buy what you're told you should
- // want ? Get out of your apartment . Meet a member of the opposite sex. Stop the
- // excessive shopping and self-improvement . Quit your boring job.
- // Start a fight. Prove you're alive. If you don't claim your humanity you'll become a
- // statistic. You've been warned !
- // Description :
- // Date : 2019-07-16
- // Time : 01:18:20
- // Directory : c:\Users\Lenovo\cpPractise\deliberatePractise\code_folder
- // FilePath : c:\Users\Lenovo\cpPractise\deliberatePractise\code_folder\FromStoT.cpp
- //==================================================================================================
- #include <bits/stdc++.h>
- #define LL long long
- #define endl "\n"
- using namespace std ;
- //
- template < typename T >
- inline T read( T &x )
- {
- x = 0 ;
- int f = 0 ;
- char ch = getchar() ;
- while( ch < '0' || ch > '9' ) {
- f |= ( ch == '-' ) , ch = getchar() ;
- }
- while( ch >= '0' && ch <= '9' ) {
- x = ( x << 1 ) + ( x << 3 ) + ch - '0' , ch = getchar() ;
- }
- return x = f ? -x:x ;
- }
- //
- void printQueue( queue<char>q )
- {
- queue<char>temp = q ;
- while( ! temp.empty() ) {
- cout << temp.front() ;
- temp.pop() ;
- }
- cout << endl ;
- }
- int main( void )
- {
- //ios_base::sync_with_stdio( false ) ; cin.tie( NULL ) ; cout.tie( NULL ) ;
- #ifndef ONLINE_JUDGE
- freopen( "input.txt" , "r" , stdin ) ;
- freopen( "output.txt" , "w" , stdout ) ;
- #endif
- int q ;
- cin >> q ;
- while( q-- ) {
- string s , t , p ;
- cin >> s >> t >> p ;
- if( s.size() > t.size() ) {
- cout << "NO\n" ;
- continue ;
- }
- else if( s.size() == t.size() && s != t ) {
- cout << "NO\n" ; continue ;
- }
- else if( s == t ) {
- cout << "YES\n" ;
- continue ;
- }
- int sa[26] , ta[26] , pa[26] ;
- memset( sa , 0 , sizeof( sa ) ) ;
- memset( ta , 0 , sizeof( ta ) ) ;
- memset( pa , 0 , sizeof( pa ) ) ;
- for( int i = 0 ; i < s.size() ; i++ ) sa[ s[i] - 'a' ]++ ;
- for( int i = 0 ; i < t.size() ; i++ ) ta[ t[i] - 'a' ]++ ;
- for( int i = 0 ; i < p.size() ; i++ ) pa[ p[i] - 'a' ]++ ;
- bool flag = false ;
- for( int i = 0 ; i < 26 ; i++ ) {
- if( sa[i] > ta[i] ) {
- flag = true ;
- break ;
- }
- }
- if( flag == true ) {
- cout << "NO\n" ; continue ;
- }
- for( int i = 0 ; i < 26 ; i++ ) {
- if( ta[i] > ( sa[i] + pa[i] ) ) {
- flag = true ;
- break ;
- }
- }
- if( flag == true ) {
- cout << "NO\n" ; continue ;
- }
- queue < char > sq , tq ;
- for( int i = 0 ; i < s.size() ; i++ ) {
- for( int j = 0 ; j < t.size() ; j++ ) {
- if( s[i] == t[j] && ta[ t[j] - 'a' ] > 0 ) {
- ta[ t[j] - 'a' ]-- ;
- sq.emplace( s[i] ) ;
- break ;
- }
- }
- }
- for( int i = 0 ; i < t.size() ; i++ ) {
- for( int j = 0 ; j < s.size() ; j++ ) {
- if( t[i] == s[j] && sa[ s[j] - 'a' ] > 0 ) {
- sa[ s[j] - 'a' ]-- ;
- tq.emplace( s[j] ) ;
- break ;
- }
- }
- }
- // printQueue( sq ) ;
- // printQueue( tq ) ;
- while ( !tq.empty() )
- {
- if( tq.front() != sq.front() ) {
- flag = true ;
- break ;
- }
- tq.pop() ; sq.pop() ;
- }
- if( flag == true ) {
- cout << "NO\n" ; continue ;
- }
- cout << "YES\n" ;
- }
- #ifndef ONLINE_JUDGE
- cout << "\nTime Elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " sec\n" ;
- #endif
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement