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<cstdio>
#include<cctype>
#include<cstdlib>
#include<string>
using namespace std;
int pos;
string parse;
/*
class Parsing{
private:
  string parse;
  int pos;
public:

  Parsing(string s){
    parse = s;
    pos = 0;
  }
*/

int fact();
int term();
int expression();

  int fact(){
    if(parse[pos] == '('){
      pos++;
      int p = expression();
      pos++;
      return p;
    }else{
      string p;
      p.clear();
      while('0' <= parse[pos] && parse[pos] <= '9'){
	//p *= 10;
	//p += parse[pos]-'0';
	p += parse[pos];
	pos++;
      }
      return (atoi)(p.c_str());
    }
  }

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

 int expression(){
    int p = term();
    while(parse[pos] == '+' || parse[pos] == '-'){
      if(parse[pos] == '+'){++pos;p+=term();}
      else {++pos;p-=term();}
    }
    return p;
  } 
 
/*
};
*/







int main(){
  string s;
  int N;
  cin >> N;
  while(N-- > 0){
    pos = 0;
    cin >> s;
    parse = s.substr(0,s.length()-1);
   
    //Parsing par = Parsing(s.substr(0,s.length()-1));
    //cout << par.expression() << endl;
    cout << expression() << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

int parse(string s){
    int i,j,x;
    int n = s.length();

    //cout << s << endl;

    x = 0;
    for(i=n-1; i>=0; i--){
        if( s[i] == '(' ) x++;
        if( s[i] == ')' ) x--;
        if( x == 0 && (s[i] == '+' || s[i] == '-') ) break;
    }

    if( i == -1 ){
        x = 0;
        for(i=n-1; i>=0; i--){
            if( s[i] == '(' ) x++;
            if( s[i] == ')' ) x--;
            if( x == 0 && (s[i] == '*' || s[i] == '/') ) break;
        }
    }

    if( i == -1 ){
        for(j=0; j<n; j++) if( !('0' <= s[j] && s[j] <= '9') ) break;
        if( j == n ){ // number
            return atoi(s.c_str());
        }
        // ()
        return parse(s.substr(1,s.length()-2));
    }
    else{
        int a = parse(s.substr(0,i)), b = parse(s.substr(i+1));
        switch(s[i]){
        case '+': return a + b;
        case '-': return a - b;
        case '*': return a * b;
        case '/': return a / b;
        }
    }
}

int main(){
    int T;
    string in;

    cin >> T;
    while( T-- ){
        cin >> in;
        cout << parse(in.substr(0,in.length()-1)) << endl;
    }

    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)


string foo2(string s){
	// cout<<s<<endl;
	bool f=true;
	rep(i,s.size()){
		if(i==0){
			if(s[0]=='-');
			else f=false;
		}
		else{
			if(s[i]>='0'&&s[i]<='9'){

			}
			else{
				f=false;
			}
		}
	}
	if(f) return s;
	// bool f=false;
	rep(i,s.size()){
		if(s[i]=='*'||s[i]=='/'){
			int xl=i,xr=i;
			f=true;
			while(1){
				if(xl==0) break;
				else if(s[xl-1]>='0'&&s[xl-1]<='9'){
					xl--;
				}
				else{
					
					break;
				}
			}
			while(1){
				if(xr==s.size()-1) break;
				else if(s[xr+1]>='0'&&s[xr+1]<='9'){
					xr++;
				}
				else{
					
					break;
				}
			}
			stringstream ss1,ss2;
			// cout<<s.substr(xl,xr-xl+1)<<endl;
			ss1<<s.substr(xl,xr-xl+1);
			int a,b;
			char t;
			ss1>>a;
			// cout<<"a "<<a<<endl;
			ss1>>t;
			ss1>>b;
			ss2<<s.substr(0,xl);
			int tt;
			if(t=='*'){
				tt=a*b;
			}
			else{
				tt=a/b;
			}
			ss2<<tt;
			ss2<<s.substr(xr+1);
			ss2>>s;
			// cout<<"foo2 "<<s<<" "<<endl;
			return foo2(s);
		}
	}
	rep(i,s.size()){
		if(s[i]=='+'||s[i]=='-'){
			int xl=i,xr=i;
			f=true;
			while(1){
				if(xl==0) break;
				else if(s[xl-1]>='0'&&s[xl-1]<='9'){
					xl--;
				}
				else{
					break;
				}
			}
			while(1){
				if(xr==s.size()-1) break;
				else if(s[xr+1]>='0'&&s[xr+1]<='9'){
					xr++;
				}
				else{
					break;
				}
			}
			stringstream ss1,ss2;
			ss1<<s.substr(xl,xr-xl+1);
			int a,b;
			char t;
			ss1>>a;
			ss1>>t;
			ss1>>b;
			ss2<<s.substr(0,xl);
			int tt;
			if(t=='+'){
				tt=a+b;
			}
			else{
				tt=a-b;
				// cout<<tt<<endl;
			}
			ss2<<tt;
			ss2<<s.substr(xr+1);
			ss2>>s;
			return foo2(s);
		}
	}
	return s;
}

string foo1(string s){
	// cout<<s<<endl;
	int xl=-1,xr=-1;
	rep(i,s.size()){
		if(s[i]=='('){
			xl=i;
		}
		else if(s[i]==')'){
			xr=i;
			break;
		}
	}
	if(xr!=-1){

		return foo2(s.substr(0,xl)+foo1(s.substr(xl+1,xr-xl-1))+s.substr(xr+1));
	}
	return foo2(s);
}

string solve(string s){
	return foo1(s);
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		s=s.substr(0,s.size()-1);
		s=solve(s);
		cout<<s<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <map>
#include <vector>

using namespace std;

int main(){
    int n;
    string q, a, sop;
    stack<int> numstack;
    stack<string> opstack;
    map<string, int> oprank;
	vector<string> exq;
    oprank["/"] = oprank["*"] = 2;
    oprank["+"] = oprank["-"] = 1;
	oprank["("] = 0;
    cin >> n;
    for(int i(0);i < n;++i){
        cin >> q;
		exq.clear();
		opstack.push("NOP");
        a = "";
        for(int j(0);j < q.length();++j){
            if(q[j] < '0' || '9' < q[j]){
                if(a.length() > 0) exq.push_back(a);
                a = "";
				sop = string(1, q[j]);
                if(!opstack.empty() && opstack.top() == "NOP"){
					opstack.pop();
					opstack.push(sop);
					continue;
				}
				if(sop == ")"){
					while(opstack.top() != "("){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.pop();
				}
				else if(sop == "(") opstack.push(sop);
				else if(sop == "="){
					while(!opstack.empty()){
						exq.push_back(opstack.top());
						opstack.pop();
					}
				}
				else if(oprank[sop] <= oprank[opstack.top()]){
					while(!opstack.empty() && oprank[sop] <= oprank[opstack.top()]){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.push(sop);
				}
				else opstack.push(sop);
            }
            else a += q[j];
        }
		for(string s : exq){
			if(s[0] < '0' || '9' < s[0]){
				int x, y;
				y = numstack.top();
				numstack.pop();
				x = numstack.top();
				numstack.pop();
				if(s == "+"){
					numstack.push(x + y);
				}
				else if(s == "-"){
					numstack.push(x - y);
				}
				else if(s == "*"){
					numstack.push(x * y);
				}
				else if(s == "/"){
					numstack.push(x / y);
				}
			}
			else numstack.push(stoi(s));
		}
		cout << numstack.top() << endl;
		numstack.pop();
    }
    return 0;
}