1194C - From S To T - CodeForces Solution


implementation strings *1300

Please click on ads to support us..

Python Code:

from collections import*
I=input
for _ in[0]*int(I()):
 s=1,*I(),0;t,p=I(),Counter(I());i=1
 for c in t:
  if c==s[i]:i+=1
  elif p[c]:p[c]-=1
  else:i=0
 print('YNEOS'[s[i]!=0::2])

C++ Code:

#include <bits/stdc++.h>
 
using namespace std;

//... Gmail: [email protected]
//... Facebook: https://www.facebook.com/profile.php?id=100009621791250
//... Github: https://github.com/ahnafshahrear
 
typedef long long int i64;
typedef unsigned long long int ui64;

#define vt vector
#define pb push_back
#define Size(v) (int)(v.size())
#define Full(v) v.begin(), v.end()
#define Sort(v) sort(Full(v))
#define ReverseSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(Full(v))
#define LineBreak cout << "\n";
#define pi 3.1415926535897932384626
#define pf first
#define ps second
#define mp make_pair
#define LowerBound(v, x) lower_bound(Full(v), x) - v.begin()
// First element not less than x - zero based index
#define UpperBound(v, x) upper_bound(Full(v), x) - v.begin()
// First element greater than x - zero based index
#define Mod 1000000007;

#define Boundary(r, c, row, column) ((r >= 0 && r < row) && (c >= 0 && c < column))
//... Works with zero based index
#define Exit(msg) {cout << msg << "\n"; return;}

#define optimize() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

template<typename T> //... cin >> vector
istream& operator>>(istream &istream, vector<T> &v) {for (auto &it : v) cin >> it; return istream;}
template<typename T> //... cout << vector
ostream& operator<<(ostream &ostream, const vector<T> &p) {for (auto &it : p) cout << it << " "; return ostream;}

template<typename T1, typename T2> //... cin >> pair
istream& operator>>(istream &istream, pair<T1, T2> &p) {return (istream >> p.first >> p.second);}
template<typename T1, typename T2> //... cout << pair
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) {return (ostream << p.first << " " << p.second);}

template<typename T>
void _debug(T a) {
    cout << a << "]\n";
}
template<typename T, typename... Args>
void _debug(T a, Args... b) {
    cout << a << ", ";
    _debug(b...);
}
template<typename... Args>
void debug(Args... b) {cout << '['; _debug(b...);}


bool sortBySec(const pair<int,int> &a, const pair<int,int> &b)
{
    return a.second < b.second;
}

int countDigit(int number) 
{
    return floor(log10(number) + 1);
}

bool isPalindrome(string s) 
{
    for (int i = 0; i < s.length() / 2; i++) 
    {
        if (s[i] != s[s.length() - i - 1]) return false;
    }
    return true;
}

void subString(string s) 
{
    for (int i = 0; i < s.size(); i++)
    {
        for (int len = 1; len <= s.size() - i; len++)
        {
            cout << s.substr(i, len) << "\n";
        }
    }
}

// Solution starts here...

void solve()
{
    string s, t, p;
    cin >> s >> t >> p;
    map<char, int> occ;
    for (char x: p)
    {
        occ[x]++;
    }
    int in = 0;
    for (char x: t)
    {
        if (x == s[in])
        {
            in++;
        }
        else if (occ[x])
        {
            occ[x]--;
        }
        else Exit("NO");
    }
    if (s.size() == in)
    {
        cout << "YES\n";
    }
    else cout << "NO\n";
}

int main()
{
    optimize()

    int testCase = 1;
    if (true)
    {
        cin >> testCase;
    }
    for (int t = 1; t <= testCase; t++)
    {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal
1299. Replace Elements with Greatest Element on Right Side
1768. Merge Strings Alternately
561. Array Partition I
1374. Generate a String With Characters That Have Odd Counts
1822. Sign of the Product of an Array
1464. Maximum Product of Two Elements in an Array
1323. Maximum 69 Number
832. Flipping an Image
1295. Find Numbers with Even Number of Digits
1704. Determine if String Halves Are Alike
1732. Find the Highest Altitude
709. To Lower Case
1688. Count of Matches in Tournament
1684. Count the Number of Consistent Strings
1588. Sum of All Odd Length Subarrays
1662. Check If Two String Arrays are Equivalent
1832. Check if the Sentence Is Pangram
1678. Goal Parser Interpretation