program main implicit none integer::N,len,i,head,tail,res,num,op integer,parameter::add=1,mult=2 character*100::S read '(a)',S res = 1 op = mult head = 1 tail = 1 len = LEN_TRIM(S) do if(S(tail:tail).eq.'+'.or. & S(tail:tail).eq.'*') then read(S(head:tail-1),*) num if(op.eq.add) then res = num + res else res = num * res end if if(tail.eq.len+1) then exit else if(S(tail:tail).eq.'+') then op = mult else op = add end if head = tail + 1 tail = tail + 1 else if (tail.eq.len+1) then read(S(head:tail-1),*) num if(op.eq.add) then res = num + res else res = num * res end if exit else tail = tail + 1 end if end do print '(i0)', res end program main