fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<cstdlib>
  4. #include<cmath>
  5.  
  6. using namespace std;
  7. int main() {
  8.  
  9. string str, st;
  10.  
  11. int index = 0, k = 0, ind = 0, index1 = 0,s = 0;
  12. long double res = 0;
  13.  
  14. char chr;
  15. getline(cin, str);
  16.  
  17. while (index < str.length())
  18. {
  19. chr = str[index];
  20. if((str[index] >= '0') && (str[index] <= '9'))
  21. {
  22. st += str[index];
  23. }
  24. else if(!st.empty())
  25. {
  26. k = atoi(st.c_str()); cout<<"k="<<k<<" ";
  27. res = res + k*pow(0.5, s); cout<<"res"<<res<<endl;
  28. st = "";
  29. }
  30. if(chr == '(')
  31. {
  32. s = s + 1;
  33. }
  34. if (chr == ')')
  35. {
  36. s = s - 1;
  37. }
  38. index++;
  39. }
  40. cout << round(res * 100) / 100.;
  41. }
Success #stdin #stdout 0s 3480KB
stdin
(12 13(14 15))
stdout
k=12 res6
k=13 res12.5
k=14 res16
k=15 res19.75
19.75