Go: package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}

C++: import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> ans = new ArrayList<Integer>();
		String line = in.readLine();

		int size = Integer.parseInt(line);

		for(int n=0; n<size; n++){
			line = in.readLine();
			int a = SC(line);
			ans.add(a);
		}

		for(int i=0; i<ans.size(); i++){
			System.out.println(ans.get(i));
		}
	}

	public int SC(String line){
		List<String> eq = new ArrayList<String>();
		int count = 0;
		while(true){
			String str = line.substring(count, count+1);
			if(str.equals("=")){
				break;
			}
			eq.add(str);
			count++;
		}

		count = 0;
		while(count < eq.size()-1){
			if(isNumber(eq.get(count)) && isNumber(eq.get(count+1))){
				String dst = eq.get(count) + eq.get(count+1);
				eq.add(count+2, dst);
				eq.remove(count);
				eq.remove(count);
			}
			else{
				count++;
			}
		}


		while(eq.size() != 1){
			//ツ環古環づ個計ツ算
			int m;
			int bra_count = 0;
			int n = eq.indexOf("(");
			if(n != -1){
				for(int i=n+1; i<eq.size(); i++){
					if(eq.get(i).equals(")") && bra_count == 0){
						eq = RangeReplace(eq, n, i);
						break;
					}
					else if(eq.get(i).equals("(")){
						bra_count++;
					}
					else if(eq.get(i).equals(")")){
						bra_count--;
					}
				}

				continue;
			}

			//ツ掛ツつッツ算ツ環づィツ算
			n = eq.indexOf("*");
			m = eq.indexOf("/");

			if(n != -1 && (m == -1 || n < m)){
				int a = Integer.parseInt(eq.get(n-1)) * Integer.parseInt(eq.get(n+1));
				eq.add(n+2, Integer.toString(a));
				eq.remove(n-1);
				eq.remove(n-1);
				eq.remove(n-1);
				continue;
			}

			if(m != -1 && (n == -1 || m < n)){
				int a = Integer.parseInt(eq.get(m-1)) / Integer.parseInt(eq.get(m+1));
				eq.add(m+2, Integer.toString(a));
				eq.remove(m-1);
				eq.remove(m-1);
				eq.remove(m-1);
				continue;
			}

			//ツ堕ォツつオツ算ツ暗クツつォツ算
			n = eq.indexOf("+");
			m = eq.indexOf("-");

			if(n != -1 && (m == -1 || n < m)){
				int a = Integer.parseInt(eq.get(n-1)) + Integer.parseInt(eq.get(n+1));
				eq.add(n+2, Integer.toString(a));
				eq.remove(n-1);
				eq.remove(n-1);
				eq.remove(n-1);
				continue;
			}

			if(m != -1 && (n == -1 || m < n)){
				int a = Integer.parseInt(eq.get(m-1)) - Integer.parseInt(eq.get(m+1));
				eq.add(m+2, Integer.toString(a));
				eq.remove(m-1);
				eq.remove(m-1);
				eq.remove(m-1);
				continue;
			}
		}

		return Integer.parseInt(eq.get(0));
	}

	public List<String> RangeReplace(List<String> eq, int s, int e){
		String part = "";

		for(int i=s+1; i<e; i++){
			part += eq.get(i);
		}

		part = Integer.toString(SC(part+"="));

		eq.add(e+1, part);

		for(int i=s; i<=e; i++){
			eq.remove(s);
		}

		return eq;
	}

	public boolean isNumber(String s){
		try{
			int n = Integer.parseInt(s);
		}catch(NumberFormatException err){
			return false;
		}

		return true;
	}
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int pos;
string str;

int exp();

int factor() {
  if(str[pos] >= '0' && str[pos] <= '9') {
    string tmp = "";
    while(str[pos] >= '0' && str[pos] <= '9') {
      tmp += str[pos++];
    }
    return atoi(tmp.c_str());
  }

  if(str[pos] == '(') {
    pos++;
    return exp();
  } else if(str[pos] == ')') {
    pos++;
    return 0;
  }
}

int term() {
  int x = factor();
  while(str[pos] == '*' || str[pos] == '/') {
    if(str[pos] == '*') {
      pos++;
      x *= factor();
    } else if(str[pos] == '/') {
      pos++;
      x /= factor();
    }
  }
  return x;
}

int exp() {
  int x = term();
  while(str[pos] == '+' || str[pos] == '-') {
    if(str[pos] == '+') {
      pos++;
      x += term();
    } else if(str[pos] == '-') {
      pos++;
      x -= term();
    }
  }
  return x;
}

main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    pos = 0;
    cin >> str;
    str = str.substr(0, str.length()-1);
    cout << exp() << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>

using namespace std;

vector<string> toReversePorland(string str){

  vector<string> hand;
  vector<string> side;
  
  for(int i = 0; i < str.size(); i++){
    if(str[i] == ' ')
      continue;
    else if(str[i] == '=')
      break;
    if(str[i] >= '0' && str[i] <= '9'){
      string num;
      while(i < str.size()){
	if(str[i] < '0' || str[i] > '9'){
	  break;
	}
	num += str[i];
	i++;
      }
      hand.push_back(num);
      i--;
    }
    else if(str[i] == '('){
      string tmp;
      tmp += str[i];
      side.push_back(tmp);
    }
    else if(str[i] == ')'){
      // ツ右ツ環古環づ慊づ可可算ツ子ツづーツ暗ェツづつつクツづつ偲ィツ個ウツづ可姪淞つキ
      for(int j = side.size()-1 ; ;j--){
	if(side[j] == "("){
	  if(j != 0){
	    vector<string> tmp;
	    for(int k = 0; k < j; k++){
	      tmp.push_back(side[k]);
	    }
	    side = tmp;
	  }
	  else
	    side.clear();
	  break;
	}
	else{
	  string tmp = side[j];
	  hand.push_back(tmp);
	}
      }
    }
    else{
      if(side.size() == 0){
	string tmp;
	tmp += str[i];
	side.push_back(tmp);
      }
      else if(str[i] == '+' || str[i] == '-'){
	if(side[side.size()-1] == "*" || side[side.size()-1] == "/"){
	  hand.push_back(side[side.size()-1]);
	  string tmp;
	  tmp += str[i];
	  side[side.size()-1] = tmp;
	}
	else{
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
      }
      else{
	if(side[side.size()-1] == "*" || side[side.size()-1] == "/"){
	  hand.push_back(side[side.size()-1]);
	  string tmp;
	  tmp += str[i];
	  side[side.size()-1] = string(tmp);
	}
	else{
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
      }
    }
  }

  for(int i = side.size()-1; i >= 0; i--){
    hand.push_back(string(side[i]));
  }
  
  return hand;
}


int calc(vector<string> str){
  stack<int> st;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == "+" || str[i] == "-" || str[i] == "*" || str[i] == "/"){
      int val[2];
      val[0] = st.top();
      st.pop();
      val[1] = st.top();
      st.pop();
      if(str[i] == "+"){
	st.push(val[0] + val[1]);
      }
      if(str[i] == "-"){
	st.push(val[1] - val[0]);
      }
      if(str[i] == "*"){
	st.push(val[0] * val[1]);
      }
      if(str[i] == "/"){
	st.push(val[1] / val[0]);
      }
    }
    else{
      st.push(atoi(str[i].c_str()));
    }
  }
  return st.top();
}

int main(){

  int n;
  string s;
  getline(cin,s);
  n = atoi(s.c_str());

  vector<string> input;
  string str;
  for(int i = 0; i < n; i++){
    getline(cin,str);
    input.push_back(str);
  }

  for(int i = 0; i < n; i++){
    str = input[i];
    // vector<string> vec = toReversePorland(str);
    // for(int i = 0; i < vec.size(); i++)
    //   cout << vec[i] << endl;
    cout << calc(toReversePorland(str)) << endl;
  }
  
  return 0;
}