Infinite Replacement Solution
Codeforces Round #786 (Div 3)
Solution :
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool iscona(string s)
{
ll n = s.size();
for (ll i = 0; i < n; i++)
{
if (s[i] == 'a')
{
return true;
}
}
return false;
}
int main()
{
ll t = 1;
cin >> t;
while (t--)
{
string s, t;
cin >> s >> t;
ll n = s.size(), m = t.size();
if (m == 1)
{
if (t[0] == 'a')
{
cout << 1 << "\n";
}
else
{
cout << (ll)pow(2, n) << "\n";
}
}
else
{
if (!iscona(t))
{
cout << (ll)pow(2, n) << "\n";
}
else
{
cout << "-1\n";
}
}
}
}
Comments
Post a Comment