#!/usr/local/bin/ruby def fmlwt(fml) #weight and formula (weight) wt={} IO::foreach("formula.dat") do |l| if l=~/([A-Z][a-z]?)\s+([\d\.]*)/ wt[$1]=$2.to_f end end fw=0 while fml.size>0 break unless m=/([A-Z][a-z]?)([\d\.]*)/.match(fml) aw=wt[m[1]] if m[2]=="" then an=1 else an=m[2].to_f end fw+=an*aw fml=m.post_match end if fw==0 then fw=1 end return fw end while true f=STDIN.readline.chomp print fmlwt(f),"\n" end