System.in.eachLine{o='' it.eachMatch(/(.*?)x(\^(.[\d.]*))?/){p,a,q,b->int c=b?b.toFloat()*10:10 c=c-76?c:77 a=(int)((a-~/\D/?a:a+1).toFloat()*c)/10 c/=10 o&&a>0?o+='+':0 o+=--c?"$a"-~/\b1$/+(c-1?'x^'+c:'x'):a} println o?:0}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).