fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. double tot=1;
  4. int loc;
  5. string a,b;
  6. int ans;
  7. int n;
  8. void try_(int i,int l)
  9. {
  10. if (i==n)
  11. ans+=(l==loc);
  12. else
  13. {
  14. if (b[i]=='+')try_(i+1,l+1);
  15. else if (b[i]=='-')try_(i+1,l-1);
  16. else {
  17. try_(i+1,l+1);
  18. try_(i+1,l-1);
  19.  
  20. }
  21. }
  22. }
  23. int main()
  24. {
  25. cin>>a>>b;
  26. int num=0;
  27. n=a.size();
  28. for (int i=0;i<n;i++){
  29. if (b[i]=='?')num++;
  30. if (a[i]=='+')loc++;
  31. else loc--;
  32. }
  33. tot=pow(2.0, 1.0*num );
  34. try_(0,0);
  35. cout<<fixed<<setprecision(12)<<ans/tot<<endl;
  36. }
Success #stdin #stdout 0s 15232KB
stdin
++++++++++
+++??++?++
stdout
0.125000000000