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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int calc(char *s, int &i, bool f = false){
  int ret = 0;
  bool flag = i >= 0 && s[i-1] == '(';
  
  for(;s[i];){
    
    if(s[i] == ')'){
      if(flag) i++;
      return ret;
    }
    
    if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/'){

      i++;
      
      if(s[i] == '('){
        i++;

        if(i-2 < 0) ret += calc(s,i);
        else if(s[i-2] == '+') ret += calc(s,i,false);
        else if(s[i-2] == '-') ret -= calc(s,i,false);
        else if(s[i-2] == '*') ret *= calc(s,i,false);
        else if(s[i-2] == '/') ret /= calc(s,i,false);

        continue;
      }
      
      if(s[i-1] == '+') ret += calc(s,i,true);
      else if(s[i-1] == '-') ret -= calc(s,i,true);
      
    }else{
      int start = i-1;
      int sum = 0;
      
      while(!(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/' || s[i] == '\0' || s[i] == ')')){
        sum *= 10;
        sum += s[i] - '0';
        i++;
      }
      /*
      debug(ret);
      debug(sum);
      debug(s[start]);
      */
      
      if(start < 0){
        ret += sum;
      }else{
        if(s[start] == '(') ret += sum;
        if(s[start] == '+') ret += sum;
        if(s[start] == '-') ret += sum;
        if(s[start] == '*') ret *= sum;
        if(s[start] == '/') ret /= sum;
      }
      
      if(f && (s[i] == '+' || s[i] == '-')){
        //debug(i);
        //debug(s[i]);
        return ret;
      }
      
      //debug(ret);
    }
  }

  //debug(s[i]);
  //debug(ret);
  
  return ret;
}


int main(){
  char s[SIZE];
  int t = 0;

  int n;

  scanf("%d",&n);

  while(n--){
    char s2[SIZE] = {};
    t = 0;
    scanf("%s",s);

    s[strlen(s)-1] = '\0';

    strcat(s2,"0+");
    strcat(s2,s);
    
    printf("%d\n",calc(s2,t));
  }
  
  return 0;
}

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

string str,t;

string calc(string s){
	
	vector<char> otr;
	otr.reserve(1000);
	vector<int> ond;
	ond.reserve(1000);
	string tmp;
	size_t now = 0;
	
	while( ~s.find_first_of("*/-+=",now) ){
		tmp = s.substr(now,s.find_first_of("*/-+=",now)-now);
		ond.push_back( atoi(tmp.c_str() ) );
		otr.push_back( s[s.find_first_of("*/-+=",now)] );
		now = s.find_first_of("*/-+=",now)+1;
	}

	for(int i=0;i<otr.size();i++){
		if(otr[i]=='*'){
			ond[i] = ond[i] * ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}else if(otr[i]=='/'){
			ond[i] = ond[i] / ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}
	}

	/*cout << ond[0];
	for(int j=0;j<otr.size();j++){
		if(otr[j]=='=')break;
		cout << " " << otr[j] << " ";
		cout << ond[j+1];
	}
	cout << endl;*/
	
	for(int i=0;i<otr.size();i++){
		if(otr[i]=='+'){
			ond[i] = ond[i] + ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}else if(otr[i]=='-'){
			ond[i] = ond[i] - ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}
	}
	stringstream ret;
	ret << ond[0];
	return ret.str();
}

string parent(string s){	
	int st,en;
	while( ~s.find("(") ){
		st = s.find("(");
		en = s.find(")");
		t = s.substr(st+1,en-st-1);
		s.replace( st , en-st+1 , parent(t+string("=")));
	}
	return calc(s);
}

int main(){
	int n;
	cin >> n;
	while(cin >> str){
		/*
		if(~s.find("(")){
			st = s.find("(");
			en = s.rfind(")");
			t = s.substr(st+1,en-st-1);
		}*/
		cout << parent(str) << endl;
	}
}

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

string S;
char U[11]="0123456789";
int junjo[4]={0,0,1,1};

long long STOI(string V){
	int LEN=V.size();
	if(LEN==0){return 0;}
	return (V[LEN - 1] - '0') + 10 * ( STOI(V.substr(0, LEN - 1)) );
}
long long calc(int L,int R){
	int K=0;
	vector<int>junjo2[4];
	for(int i=0;i<4;i++){
		junjo2[junjo[i]].push_back(i);
	}
	for(int i=0;i<4;i++){
		if(junjo2[i].size()>=1){
			for(int j=R-1;j>=L;j--){
				if(S[j]=='('){K++;}
				if(S[j]==')'){K--;}
				for(int k=0;k<junjo2[i].size();k++){
					if(junjo2[i][k]==0){
						if(S[j]=='+' && K==0){
							return calc(L,j)+calc(j+1,R);
						}
					}
					if(junjo2[i][k]==1){
						if(S[j]=='-' && K==0){
							return calc(L,j)-calc(j+1,R);
						}
					}
					if(junjo2[i][k]==2){
						if(S[j]=='*' && K==0){
							return calc(L,j)*calc(j+1,R);
						}
					}
					if(junjo2[i][k]==3){
						if(S[j]=='/' && K==0){
							return calc(L,j)/calc(j+1,R);
						}
					}
				}
			}
		}
	}
	if(S[L]=='(' && S[R-1]==')'){return calc(L+1,R-1);}
	return STOI(S.substr(L,R-L));
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>S;
		cout<<calc(0,S.size()-1)<<endl;
	}
}