Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.4 kB
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std; 
#define ll long long
string solve (string s1, string s2) {
    // Write your code here
    string ans = "";
    ll n1 = s1.size();
    ll n2 = s2.size();
    // return " - 1 ";
    ll k = n1 + n2 - 1;
    for(int i=0;i<k; ++i) ans += '!';
    ll m = 0 
    for(int i = 0; i < n2; ++i)
    {
        if( s2[i] == 'T')
        {
            m = i;
            for (int j = 0 j < n1; ++j)
            {
                if(ans[m] != '!' && ans[m] !=s1[j]) return "-1";
                ans[m] = s1[j];
                m++;
            }
        }
    }
    // for(int i = 0; i <k; ++i) if( ans[i] ==^ prime I^ prime )ans[i]=^ prime A^ prime ;
    for(int i = 0 i < n2; ++i)
    {
        if( s2[i] =='F' )
        {
            string k = "";
            for(int j = 0 j < n1; ++j)
            {
                k+=ans[i];
            }
            if (k==s1) return "-1";
        }
    }
    for(int i=0;i<k; ++i)
    if( ans[i] == '!')
    {
        int j = 0
        for(;j< 26; ++j)
        {
            ans[i]='A'+j;
            string g = "";
            for (int l = 0; l < n1; ++l)
            {
                if(l+i >= k) break; 
                g += ans[l+i];
            } 
            if(s1 != g ) break;
        } 
        if (j==27) return "-1";
    }
    return ans;
}