fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. typedef long long ll;
  5.  
  6.  
  7. vector<double> prob;
  8. void get_position(string string,double position){
  9. if(string.empty()){
  10. prob.push_back(position);
  11. return;
  12. }
  13.  
  14. if(string[0]=='+'){
  15. string = string.erase(0, 1);
  16. get_position(string,++position);
  17.  
  18. }else if(string[0]=='-'){
  19. string = string.erase(0, 1);
  20. get_position(string,--position);
  21.  
  22. }
  23. else {
  24. string = string.erase(0, 1);
  25. int temp = position;
  26. get_position(string,++position);
  27. position = temp;
  28. get_position(string,--position);
  29. }
  30.  
  31. }
  32.  
  33.  
  34. int main() {
  35. FAST
  36.  
  37. string s1,s2;
  38. cin >> s1 >> s2;
  39. double desired_pos = 0;
  40. for(auto c : s1){
  41. if(c == '+'){
  42. desired_pos++;
  43. }
  44. else{
  45. desired_pos--;
  46. }
  47. }
  48. get_position(s2,0);
  49.  
  50. cout << fixed << setprecision(12) << ((double)count(prob.begin(),prob.end(),desired_pos)/prob.size()) << " \n";
  51. // system("pause");
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
1.000000000000