package com;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Calculator {
//+-*/()
public static void main(String[] args) {
// Pattern pattern = Pattern.compile("(?<=\\d)(\\+|-|\\*|/)");
// Matcher matcher = pattern.matcher("2-4");//3*((5*(2-4))*(3-1*2))
// while(matcher.find()){
// System.out.println(matcher.group());
// };
double rs = 0;
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
rs=count(str);
System.out.println(rs);
}
public static double count(String str){
Pattern p1 = Pattern.compile("\\([^\\(^\\)]*\\)");
Matcher m1 = p1.matcher(str);
if(m1.find()){
if(m1.start()==0&&m1.end()==str.length()){
if(str.startsWith("(")&&str.endsWith(")")){
str = str.substring(1,str.length()-1);
}
}
}
double rs = 0;
Pattern pattern = Pattern.compile("\\([^\\(^\\)]*\\)");
Matcher matcher = pattern.matcher(str);
while(matcher.find()){//计算最里面的一对括号们
String str2 = matcher.group();
rs = count(str2);
str = str.replace(str2,String.valueOf(rs));
}
while(str.indexOf("(")>-1){//算完以后还有括号继续优先算
Matcher matcher2 = pattern.matcher(str);
while(matcher2.find()){
String str2 = matcher2.group();
rs = count(str2);
str = str.replace(str2,String.valueOf(rs));
}
}
rs = count2(str);
return rs;
}
private static double count2(String str) {
if(str.startsWith("(")&&str.endsWith(")")){
str = str.substring(1,str.length()-1);
}
double rs = 0;
String[] nums = str.split("(?<=\\d)(\\+|-|\\*|/)");
String[] ctrls = str.replaceAll("[0-9.]|(?
List numsList = new ArrayList();
List ctrlsList = new ArrayList();
for (String string : nums) {
numsList.add(string);
}
for (String string : ctrls) {
ctrlsList.add(string);
}
for (int i = 1; i < ctrlsList.size(); i++) {
if("*".equals(ctrlsList.get(i))||"/".equals(ctrlsList.get(i))){
double start = Double.parseDouble(numsList.get(i-1));
double end = Double.parseDouble(numsList.get(i));
if("*".equals(ctrlsList.get(i))){
rs = start*end;
}else{
rs = start/end;
}
ctrlsList.remove(i);
numsList.remove(i);
numsList.set(i-1, String.valueOf(rs));
i--;
}
}
for (int i = 1; i < ctrlsList.size(); i++) {
if("+".equals(ctrlsList.get(i))||"-".equals(ctrlsList.get(i))){
double start = Double.parseDouble(numsList.get(i-1));
double end = Double.parseDouble(numsList.get(i));
if("+".equals(ctrlsList.get(i))){
rs = start+end;
}else{
rs = start-end;
}
ctrlsList.remove(i);
numsList.remove(i);
numsList.set(i-1, String.valueOf(rs));
i--;
}
}
return rs;
}
}