Molecular Mass

I suggest you to solve your mistake if u can… I already tried to help u in finding where u r going wrong…
Though I can try and I think I can solve this error if u want me to…
but I strongly recommend you to solve it yourself because its better that way…
Competitive programming is about learning how to learn and that is(solving ur problems( i.e your bugs) by yourself) what you learn from it…

PS: I think you can solve this error (by seeing ur level of coding)… you just need some determination…
But do let me know if u want me to solve it…

and thanks for pointing out my mistake of multiplication in above calculation

I updated my algorithm now it solves all above mention formulae by u correctly but still fails for sixth time :frowning:
I have updated my solution link above .
So can u plz point my mistake or give corner case for which my code fails so again i can update by this way eventually i would get it AC

yup sure
(CHOH)3(H)4
try this and compare it with
((CHOH)3(H)4) which gives correct answer…

Plz someone give algorithm for this problem. I have tried many times but fails

I don’t know how to make computer understand whether last digit if encountered in chemical formulae is to be multiplied for entire formula or preceding group only.

For eg:

(CHOH)3(H)4 // here 4 to be multiplied only with H

((CH)2(OH2H)(C(H))O)4 // here 4 to be multiplied for entire whole formulae

1 Like

Maybe using use another stack would help… push pop values u need according to brackets

#HERE is my accepted solution in case you need reference…

1 Like

#HERE is my accepted solution in case you need reference…

hehe btw I liked your name… “code man” :smiley:

hehe btw I liked your name… “code man” :smiley:
and do ask if u dont understand anything… :slight_smile:

1 Like

Here I have started rule’s number from 0 as everything in coding starts from 0 and even we have 0th law of thermodynamics :slight_smile:

no reply for such a big answer :frowning: !!

thanks bro I forgot i liked ur answer i have not implemented yet.
Can u plz answer my next question “Shocked !!”(title) question mentioned on list (discussion)

okay welcome :slight_smile:

while thinking too much I have few doubts:

  1. I tried without zero then why its not working
  2. 3rd point in ur algorithm im not clear. Can u plz implement for this two contrast egs:-

((CH)2(OH2H)(C(H))O)3

(CHOH)3(H9H)3

I’m only not understanding when digit is encountered it will be multiplied with entire formula or only preceding group how to code this part.

have you seen my code ?? It would be helpful if u see my answer and code simultaneously…
At this time I am on a live contest so ll reply u later…

do{
flag=true;

            t=str.top();
            str.pop();
            
            switch(t){
                case '(': 
                            v=val.top();
                            val.pop();
                            v=(v*temp)+val.top();
                            break; 
                case 'C':
                            v=val.top();
                            v+=12*temp2;
                            break;
                case 'H':  
                            v=val.top();
                            v+=1*temp2;
                            break;
                case 'O':
                            v=val.top();
                            v+=16*temp2;
                            break;
                default :
                            flag=false; // make it false if t is a number
                            temp2=t-'0';    
            }
            
            if(flag){ // if t was not a number
                temp2=1;
                val.pop();
                val.push(v);
            }
            
        }  
        while(t!='(');

this is what my third point says @code_man

actually this contains 3rd and 4th point