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<map>
using namespace std;
#define ans pair<int, int>
ans equation(string s, int p = 0);
ans factor(string s, int p = 0);
ans term(string s, int p = 0);
int main(){
  int n;
  cin >>n;
  while(n--){
    string s;
    cin >>s;
    ans r = equation(s);
    cout <<r.first<<endl;
  }
  return 0;
}
ans equation(string s, int p){
  ans r = factor(s,p);
  while(s[r.second] == '+' || s[r.second] == '-'){
    ans r_dash = factor(s,r.second+1);
    if(s[r.second] == '+'){r.first += r_dash.first;}
    if(s[r.second] == '-'){r.first -= r_dash.first;}
    r.second = r_dash.second;
  }
  return r;
}
ans factor(string s, int p){
  ans r = term(s,p);
  while(s[r.second] == '*' || s[r.second] == '/'){
    ans r_dash = term(s,r.second+1);
    if(s[r.second] == '*'){r.first *= r_dash.first;}
    if(s[r.second] == '/'){r.first /= r_dash.first;}
    r.second = r_dash.second;
  }
  return r;
}
ans term(string s, int p){
  if(s[p] == '('){
    ans r = equation(s,p+1);
    r.second++;
    return r;
  }
  else{
    int v = 0;
    while(isdigit(s[p])){
      v = v*10+s[p++]-'0';
    }
    return ans(v,p);
  }
}

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;
      tmp = 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++: /*
  Expr = Term { (+|-) Term}
  Term = Fact { (*|/) Fact}
  Fact = (Expr) | number

*/

#include<iostream>
#include<cstdlib>
using namespace std;


typedef pair<int,const char*>parsed;


parsed expr(const char *p);
parsed term(const char *p);
parsed fact(const char *p);


parsed expr(const char *p)
{
  parsed r=term(p);
 
 while(*r.second=='+'||*r.second=='-'){
    char op =*r.second;
    int tmp=r.first;
    r=term(r.second+1);
    if(op=='+')r.first=tmp+r.first;
    else r.first=tmp-r.first;
  }
  return r;
}

parsed term(const char *p)
{
  parsed r=fact(p);
  while(*r.second=='*'||*r.second=='/'){
    char op=*r.second;
    int tmp=r.first;
    r=fact(r.second+1);
    if(op=='*')r.first=tmp*r.first;
    else r.first=tmp/r.first;
  }
  return r;
}

parsed fact(const char *p)
{
  if(isdigit(*p)){
    int t=*(p++)-'0';
    while(isdigit(*p))t=t*10+*(p++)-'0';
    return parsed(t,p);
  }
  else if(*p=='('){
    parsed r=expr(p+1);
    if(*r.second!=')')exit(0);
    return parsed(r.first,r.second+1);
  }
  else exit(0);
}

int main()
{
  string str;
  int n;
  cin>>n;
  while(n--){
	  cin>>str;
    cout<<expr(str.c_str()).first<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <map>
#include <string>
#include <cctype>
using namespace std;

map<char,int> order;
string S; size_t cur=0;
stack<int> num,rnum;
stack<char> op,rop;

int digit(){
	int n=S[cur++]-'0';
	return n;
}

int number(){
	int n=digit();
	while(isdigit(S[cur]))
		n=n*10+digit();
	return n;
}

void calc(){
	int b=num.top();num.pop();
	int a=num.top();num.pop();
	char o=op.top();op.pop();
	int c;
	switch(o){
		case '+' :
			c=a+b;
			break;
		case '-' :
			c=a-b;
			break;
		case '*' :
			c=a*b;
			break;
		case '/' :
			c=a/b;
			break;
		default :
			break;
	}
	num.push(c);
	return ;
}

void calc2(){
	int a=rnum.top();rnum.pop();
	int b=rnum.top();rnum.pop();
	char o=rop.top();rop.pop();
	int c;
	switch(o){
		case '+' :
			c=a+b;
			break;
		case '-' :
			c=a-b;
			break;
		case '*' :
			c=a*b;
			break;
		case '/' :
			c=a/b;
			break;
		default :
			break;
	}
	rnum.push(c);
	return ;
}

int exp(){
	cur =0;
	int smax=S.size();
	while(cur < smax-1){
		//cout << cur << endl;
		if(isdigit(S[cur])){
			int a=number();
			num.push(a);
		}else if(!op.empty()&&op.top()!='('&&op.top()!=')'&& order[S[cur]] >= order[op.top()]){ //計算順序については改善の余地あり (　は最小に
			calc();
			op.push(S[cur++]);
		}else if(S[cur] == ')' ){
			rnum.push(num.top());num.pop();
 			while(!op.empty()&&op.top()!='('){
				rop.push(op.top());op.pop();
				rnum.push(num.top());num.pop();
			}
			while(!rop.empty())
				calc2();
			num.push(rnum.top());rnum.pop();
			//cout << num.top() << endl;
			op.pop();cur++;
		}else{//ひとまず終了　演算記号のチェックも入れる
			//	cout << "come" << endl;
			op.push(S[cur++]);
		}
	}
	cout << num.top() << endl;//
	int tmp=num.top();num.pop();
	cout << num.top() << endl;//
	num.push(tmp);

	rnum.push(num.top());num.pop();
	while(!op.empty()&&op.top()!='('){
		rop.push(op.top());op.pop();
		rnum.push(num.top());num.pop();
	}
	while(!rop.empty())
		calc2();
	num.push(rnum.top());rnum.pop();
	//cout<< " check "  << op.empty() << endl;
	int ans=num.top();
	num.pop();
	return ans;
}

int main(void){
	order['+']=2;
	order['-']=2;
	order['*']=1;
	order['/']=1;
	//cout << order['('] << endl;
	int n;
	cin >> n;
	while(n--){
		cin >> S;
		cout << exp() << endl;
	}
	return 0;
}