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++: #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;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<deque>
#include<map>
#include<utility>
using namespace std;
int main(void)
{
	map<char, int> priority;
	priority['*'] = 30;
	priority['/'] = 30;
	priority['+'] = 10;
	priority['-'] = 10;
	priority['('] = 0;
	priority[')'] = 0;
	char str[128], *p,*next;
	int v, n;

	scanf("%d", &n);
	while(n--)
	{
		scanf("%s",str);
		deque<pair<char,int> > source;	
		stack<char> subStack;

		p = str;
		while(*p)
		{
			if(isdigit(*p))
			{
				v = strtol(p, &next, 10);
				source.push_back(make_pair('\0', v));
				p = next;
			}
			else
			{
				switch(*p)
				{
				case '(':
					subStack.push(*p);
					break;
				case ')':
					while(subStack.top() != '(')
					{
						source.push_back(make_pair(subStack.top(),0));
						subStack.pop();
					}
					subStack.pop();
					break;
				case '*':
				case '/':
				case '+':
				case '-':
					while(!subStack.empty() && priority[*p] <= priority[subStack.top()])
					{
						source.push_back(make_pair(subStack.top(),0) );
						subStack.pop();
					}
					subStack.push(*p);
					break;
				case '=':
					break;
				}
				++p;
			}
		}
		while(!subStack.empty())
		{
			source.push_back(make_pair(subStack.top(),0));
			subStack.pop();
		}
		stack<int> s;
		while(!source.empty())
		{
			if(source.front().first)
			{
				int lhv, rhv;
				rhv = s.top();s.pop();
				lhv = s.top();s.pop();
				switch(source.front().first)
				{
				case '+': s.push(lhv+rhv); break;
				case '-': s.push(lhv-rhv); break;
				case '*': s.push(lhv*rhv); break;
				case '/': s.push(lhv/rhv); break;
				}
			}
			else s.push(source.front().second);
			source.pop_front();
		}
		printf("%d\n", s.top());
		s.pop();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int exp(string&, int&);
int term(string&, int&);
int factor(string&, int&);

int exp(string& str, int& p){
  int res = term(str, p);
  while(str[p] == '+' || str[p] == '-'){
    if(str[p] == '+'){
      p++;
      res += term(str, p);
    }else{
      p++;
      res -= term(str, p);
    }
  }
  return res;
}

int term(string& str, int& p){
  int res = factor(str, p);
  while(str[p] == '*' || str[p] == '/'){
    if(str[p] == '*'){
      p++;
      res *= factor(str, p);
    }else{
      p++;
      res /= factor(str, p);
    }
  }
  return res;
}

int factor(string& str, int& p){
  int res = 0;
  int keta = 1;
  if(str[p] == '('){
    while(str[p] != ')'){
      p++;
      res += exp(str, p);
    }
  }else{
    while(isdigit(str[p])){
      res += str[p] * keta - '0';
      p++; keta *= 10;
    }
  }
  return res;
}


int main(void){
  int n; cin >> n;
  while(n--){
    int p=0;
    string str;
    cin >> str;
    cout << exp(str, p) << endl;
  }
  return 0;
}

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

int getNumber( string& str, int* index )
{
	int ret = 0;
	while( *index < (int)str.size() ){
		if( str[ *index ] < '0' || str[ *index ] > '9' ){
			break;
		}
		ret *= 10;
		ret += ( str[ *index ] - '0' );
		++(*index);
	}
	return ret;
}

int rec( string& formula, int* index )
{
	int ret = 0;
	vector<int> num_list;
	vector<char> sign_list( 1, '.' );
	bool end = false;

	while( !end && *index < (int)formula.size() ){
		if( formula[ *index ] >= '0' && formula[ *index ] <= '9' ){
			num_list.push_back( getNumber( formula, index ) );
			continue;
		}else{
			switch( formula[ *index ] ){
				case '(':
					++(*index);
					num_list.push_back( rec( formula, index ) );
					break;
				case ')':
				case '=':
					++(*index);
					end = true;
					break;
				default:
					sign_list.push_back( formula[ *index ] );
					++(*index);
					break;
			}
		}
	}

	vector<int> num2_list;
	vector<char> sign2_list( 1, '.' );

	for( int i = 0; i < (int)num_list.size(); ++i ){
		int num = num_list[ i ];
		switch( sign_list[ i ] ){
			case '.':
				ret = num;
				break;
			case '*':
				ret *= num;
				break;
			case '/':
				ret /= num;
				break;
			default:
				num2_list.push_back( ret );
				ret = num;
				sign2_list.push_back( sign_list[ i ] );
				break;
		}
	}
	num2_list.push_back( ret );

	for( int i = 0; i < (int)num2_list.size(); ++i ){
		int num = num2_list[ i ];
		switch( sign2_list[ i ] ){
			case '.':
				ret = num;
				break;
			case '+':
				ret += num;
				break;
			case '-':
				ret -= num;
				break;
		}
	}

	return ret;
}

int solve( string& formula ){
	int index = 0;
	return (int)rec( formula, &index );
}

int main()
{
	int n;
	cin >> n;

	for( int i = 0; i < n; ++i ){
		string formula;
		cin >> formula;
		cout << solve( formula ) << endl;
	}

	return 0;
}