Molecular mass of a compund MMASS

I have tried all the testcases, and my code is working fine.

but it’s still showing me WA, there might be a corner case which i am missing,
I request you to help me correct my code…i am using c++

problem link:
my code:
problem code: MMASS 

I am really thankful to you..

Input : HH(HH)(HH)2
Correct Output : 8
Your Output : 10

… and a lot more cases like this… The problem in your code is whenever your code sees something like “)NUM” you are multiplying the current sum with NUM instead you should multiply to only that part of sum which results from a pair or parentheses.

one more doubt on same question :smiley:

##HERE is my answer to same question… I guess you both have same type of mistake of not identifying matching brackets…

Feel free to ask queries further… trying to avoid writing again same type of answer again… so U can have a look at that link and reply if u still have any query…