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 <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] == ')' ){
			if(!op.empty()&&op.top()!='(')
				calc();
			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++]);
		}
	}

	if(op.size()>=2){
		char op1,op2;
		op1=op.top();op.pop();op2=op.top();
		op.push(op1);
		if(order[op1]<order[op2])
			calc();
	}
	//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;
}

C++: 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cctype>
#include <cassert>

using namespace std;

int n;
string S;
int cur;

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

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

int expression();
int factor(){
	if (S[cur] != '(') return number();
	cur++;
	int n = expression();
	cur++;
	return n;	
}

int term(){
	int sum = factor();
	while(cur < S.size() && (S[cur] == '*' || S[cur] == '/')){
		char op = S[cur];
		cur++;
		int b = factor();
		if(op == '*') sum *= b;
		else sum /= b;
	}
	return sum;
}

int expression(){
	int sum = term();
	while(cur < S.size() && (S[cur] == '+' || S[cur] == '-')){
		char op = S[cur];
		cur++;
		int b = term();
		if(op == '+') sum += b;
		else sum -= b;
	}
	return sum;
	
}


int main(void){

	cin >> n;

	for(int i = 0; i < n; i++){
		cur = 0;
		cin >> S;
		S.resize(S.size()-1);
		cout << expression() << endl;
	}
	
    return 0;
}

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

using namespace std;

using State = string::const_iterator;
             
int expression(State& s);

int number(State& s)
{
	int res = 0;
	while (isdigit(*s)) {
		res *= 10;
		res += *s - '0';
		s++;
	}
	return res;
}

int factor(State& s)
{
	if (*s == '(') {
		s++;
		int res = expression(s);
		s++;
		return res;
	} else {
		return number(s);
	}
}

int term(State& s)
{
	int res = factor(s);
	while (true) {
		if (*s == '*') {
			s++;
			res *= factor(s);
		} else if (*s == '/') {
			s++;
			res /= factor(s);
		} else {
			break;
		}
	}
	return res;
}

int expression(State& s)
{
	int res = term(s);
	while (true) {
		if (*s == '+') {
			s++;
			res += term(s);
		} else if (*s == '-') {
			s++;
			res -= term(s);
		} else {
			break;
		}
	}
	return res;
}

int main()
{
    int q;
    cin >> q;
    while (q--) {
        string st;
        cin >> st;
		State s = st.begin();
        cout << expression(s) << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;
int p;

int exp(string str);
int term(string str);
int fact(string str);

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

int term(string str)
{
	int val = fact(str);
	while(str[p] == '*' || str[p] == '/'){
		if(str[p++] == '*'){
			val *= fact(str);
		} else {
			val *= fact(str);
		}
	}
	
	return val;
}

int fact(string str)
{
	int val = 0;
	if(str[p] == '('){
		p++;
		val = exp(str);
		p++;
	} else {
		string s = "";
		while('0' <= str[p] && str[p] <= '9'){
			s += str[p++];
		}
		val = atoi(s.c_str());
	}
	
	return val;
}

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

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int solve(string& s, int& i)
{
    int a = 0;
    int b = 0;
    char prev = '+';
    for(;;){
        int x = 0;
        if(s[i] == '('){
            ++ i;
            x += solve(s, i);
        }else{
            while('0' <= s[i] && s[i] <= '9'){
                x *= 10;
                x += s[i] - '0';
                ++ i;
            }
        }

        if(prev == '+'){
            a += b;
            b = x;
        }else if(prev == '-'){
            a += b;
            b = -x;
        }else if(prev == '*'){
            b *= x;
        }else{
            b /= x;
        }

        if(s[i] == ')' || s[i] == '=')
            break;

        prev = s[i];
        ++ i;
    }

    return a + b;
}

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

    while(--n >= 0){
        string s;
        cin >> s;
        int i = 0;
        cout << solve(s, i) << endl;
    }

    return 0;
}