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<vector>
#include<string>
#include<algorithm>
#include<sstream>

void erase(std::vector<std::string>&v,int e,int f){
	for(int i=e;i<v.size()-f;i++)v[i]=v[i+f];
}

std::string solve(std::string str){
	std::vector<std::string>v;
	int a,b,c,d,v_size,j=0;
	for(int i=0;i<=str.size();i++){
		if(i==str.size()||str[i]=='+'||str[i]=='-'||str[i]=='*'||str[i]=='/'){
			v.push_back(str.substr(j,i-j));
			v.push_back(str.substr(i,1));
			j=i+1;
		}
	}
	v_size=v.size();
	a=std::find(v.begin(),v.begin()+v_size,"*")-v.begin();
	while(a!=v_size){
		int p=std::stoi(v[a-1]),q=std::stoi(v[a+1]);
		std::stringstream z;
		z<<p*q;z>>v[a-1];
		erase(v,a,2);v_size-=2;
		a=std::find(v.begin(),v.begin()+v_size,"*")-v.begin();
	}
	b=std::find(v.begin(),v.begin()+v_size,"/")-v.begin();
	while(b!=v_size){
		int p=std::stoi(v[b-1]),q=std::stoi(v[b+1]);
		std::stringstream z;
		z<<p/q;z>>v[b-1];
		erase(v,b,2);v_size-=2;
		b=std::find(v.begin(),v.begin()+v_size,"/")-v.begin();
	}
	c=std::find(v.begin(),v.begin()+v_size,"+")-v.begin();
	while(c!=v_size){
		int p=std::stoi(v[c-1]),q=std::stoi(v[c+1]);
		std::stringstream z;
		z<<p+q;z>>v[c-1];
		erase(v,c,2);v_size-=2;
		c=std::find(v.begin(),v.begin()+v_size,"+")-v.begin();
	}
	d=std::find(v.begin(),v.begin()+v_size,"-")-v.begin();
	while(d!=v_size){
		int p=std::stoi(v[d-1]),q=std::stoi(v[d+1]);
		std::stringstream z;
		z<<p-q;z>>v[d-1];
		erase(v,d,2);v_size-=2;
		d=std::find(v.begin(),v.begin()+v_size,"-")-v.begin();
	}
	return v[0];
}

int main(){
	int n;
	std::string str;
	std::cin>>n;
	for(int i=0;i<n;i++){
		std::cin>>str;
		int a=str.find('('),b=str.find(')');
		while(a!=-1){
			std::string astr=str.substr(a+1,(b-1)-a);
			str.erase(a,b-a+1);
			str.insert(a,solve(astr));
			a=str.find('('),b=str.find(')');
		}
		std::cout<<solve(str.substr(0,str.size()-1))<<std::endl;
	}
	return 0;
}

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

std::string find(std::vector<std::string>&v, int a, bool b){

	std::string res;

	if (b){
		for (int i = a - 1; i >= 0; i--){
			if (v[i] != "T"){
				res = v[i];
				v[i] = "T";
				break;
			}
		}
	}

	if (!b){
		for (int i = a + 1; i < v.size(); i++){
			if (v[i] != "T"){
				res = v[i];
				v[i] = "T";
				break;
			}
		}
	}

	return res;
}

int toint(std::string str){

	int res;
	std::stringstream z;

	z << str;
	z >> res;

	return res;

}

std::string tostring(int a){

	std::string str;
	std::stringstream z;

	z << a;
	z >> str;

	return str;

}

std::string keisan(std::string lhs, std::string rhs, int t){

	int a, b, c;

	a = toint(lhs);
	b = toint(rhs);

	if (t == 1)c = a + b;
	if (t == 2)c = a - b;
	if (t == 3)c = a * b;
	if (t == 4)c = a / b;

	return tostring(c);

}

std::string keisan2(std::vector<std::string> &v){

	int res = 0;

	for (int i = 0, j = 0, k = 0; i < v.size(); i++){
		if (v[i] == "(")j = i, k++;
		if (v[i] == ")"){
			k--;
			if (k == 0){
				std::vector<std::string>w;
				for (int p = j + 1; p < i; p++)w.push_back(v[p]);
				v[j] = keisan2(w);
				for (int p = j + 1; p <= i; p++)v[p] = "T";
			}
		}
	}



	for (int i = 0; i < v.size(); i++){
		if (v[i] == "*"){
			v[i - 1] = keisan(find(v, i, 1), find(v, i, 0), 3);
			v[i] = v[i + 1] = "T";
		}
		if (v[i] == "/"){
			v[i - 1] = keisan(find(v, i, 1), find(v, i, 0), 4);
			v[i] = v[i + 1] = "T";
		}
	}

	for (int i = 0; i < v.size(); i++){
		if (v[i] == "+"){
			v[i - 1] = keisan(find(v, i, 1), find(v, i, 0), 1);
			v[i] = v[i + 1] = "T";
		}
		if (v[i] == "-"){
			v[i - 1] = keisan(find(v, i, 1), find(v, i, 0), 2);
			v[i] = v[i + 1] = "T";
		}
	}

	for (int i = 0; i < v.size(); i++)res = std::max(res, toint(v[i]));

	return tostring(res);

}


int main(){

	std::vector<std::string> v;

	std::string str;
	std::cin >> str;

	for (int i = 0, j = 0; i < str.size(); i++){

		if (!(str[i] >= '0'&&str[i] <= '9')){
			if (i - j > 0)v.push_back(str.substr(j, i - j));
			v.push_back(str.substr(i, 1));
			j = i + 1;
		}
	}

	std::cout << keisan2(v) << std::endl;

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

string s;
int iter;

ll dfs();

ll dfs2(ll val,int op){
  ll tmp = 0;
  while(true){
    if('0'<=s[iter]&&s[iter]<='9'){
      tmp *= 10;
      tmp += s[iter]-'0';
    }else if(s[iter]=='('){
      ++iter;
      if(op) val *= dfs();
      else val /= dfs();
    }else if(s[iter]==')' || s[iter]=='=' || s[iter]=='+' || s[iter]=='-'){
      if(op) val *= tmp;
      else val /= tmp;
      --iter;
      return val;
    }else if(s[iter]=='*' || s[iter]=='/'){
      if(op) val *= tmp;
      else val /= tmp;
      op = s[iter]=='*'?1:0;
      tmp = 0;
    }
    if(iter>=s.size()){
      --iter;--iter;
      return val;
    }
    ++iter;
  }
}

ll dfs(){
  ll val = 0;
  ll tmp = 0;
  int op = 1; // op==1?'+':'-'
  while(true){
    if('0'<=s[iter]&&s[iter]<='9'){
      tmp *= 10;
      tmp += s[iter]-'0';
    }else if(s[iter]=='('){
      ++iter;
      tmp = dfs();
    }else if(s[iter]==')' || s[iter]=='='){
      val += op*tmp;
      tmp = 0;
      return val;
    }else if(s[iter]=='+'){
      val += op*tmp;
      tmp = 0;
      op = 1;
    }else if(s[iter]=='-'){
      val += op*tmp;
      tmp = 0;
      op = -1;
    }else if(s[iter]=='*' || s[iter]=='/'){
      ++iter;
      val += op*dfs2(tmp,s[iter-1]=='*'?1:0);
      tmp = 0;
    }
    if(iter>=s.size()){
      --iter;--iter;
      return val;
    }
    ++iter;
  }
}

int main(){
  int n;
  cin>>n;
  while(n--){
    cin>>s;
    iter = 0;
    cout<<dfs()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;

int expr();
int term();
int fact();

char *p;
char inp[101];

int main(){
    int n;
    cin >> n;
    cin.ignore();
    while (n--){
	cin.getline(inp, sizeof(inp));
	p = inp;
	cout << expr() << endl;
    }
}

int expr(){
    int m = 0;
    m = term();
    while (*p == '+' || *p == '-'){
	if (*p == '+')
	    p++, m += term();
	else if (*p == '-')
	    p++, m -= term();
    }
    return m;
}

int term(){
    int m = 0;
    m = fact();
    while (*p == '*' || *p == '/'){
	if (*p == '*')
	    p++, m *= fact();
	else if (*p == '/')
	    p++, m /= fact();
    }
    return m;
}

int fact(){
    int m = 0;
    if (*p == '('){
	p++;
	m = expr();
	p++;
	return m;
    }
    else {
	while ('0' <= *p && *p <= '9'){
	    m *= 10;
	    m += *p - '0';
	    p++;
	}
    }
    return m;
}