Untitled

 avatar
user_5668965
c_cpp
10 days ago
881 B
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

#define ll long long int

ll ans,num;
void count(string &s2,ll n,ll sum,ll cnt)
{
    if(n==0) 
    {
        if(sum==cnt) ans++;
        num++;
        return;
    }
    if(s2[n-1]=='?')
    {
        count(s2,n-1,sum+1,cnt);
        count(s2,n-1,sum-1,cnt);
    }
    else if(s2[n-1]=='+')
    {
        count(s2,n-1,sum+1,cnt);
    }
    else if(s2[n-1]=='-')
    {
        count(s2,n-1,sum-1,cnt);
    }
}


void solve()
{   
   string s1,s2;
   cin>>s1>>s2;
   ll cnt=0;
   f(i,0,s1.length()) 
   {
        if(s1[i]=='+') cnt++;
        else cnt--;
   }
   count(s2,s2.length(),0LL,cnt);
   cout<<fixed<<setprecision(12)<<((double)(ans)/(double)(num));
   
}

// 1 3 6 11 11

int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--) 
        solve();
    return 0;
}
Leave a Comment