a53

Atomi

a53
Mar 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. char s[256];
  6. int A[1000] , B[1000] , n , *v;
  7. int main()
  8. {
  9. cin >> s;
  10. n = 1;
  11. for(unsigned int i = 0 ; i < strlen(s) ; i ++)
  12. if(s[i] == '(')
  13. n++,A[n] = B[n] = 0;
  14. else
  15. if(s[i] == ')')
  16. {
  17. int x = 0;
  18. if(s[i+1]>='0' && s[i+1] <='9')
  19. {
  20. while(s[i+1]>='0' && s[i+1] <='9')
  21. x = 10 * x + s[i+1] - '0', i ++;
  22. }
  23. else
  24. x = 1;
  25. A[n-1] += A[n] * x, B[n-1] += B[n] * x , n --;
  26. }
  27. else
  28. {
  29. //este A sau B
  30. if(s[i] == 'A')
  31. v = A;
  32. else
  33. v = B;
  34. int x = 0;
  35. if(s[i+1]>='0' && s[i+1] <='9')
  36. {
  37. while(s[i+1]>='0' && s[i+1] <='9')
  38. x = 10 * x + s[i+1] - '0', i ++;
  39. }
  40. else
  41. x = 1;
  42. v[n] += x;
  43. }
  44. cout << A[1] << " " << B[1];
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment