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>

using namespace std;

int pri(char ch) 
{
    if (ch == '*' || ch == '/')
        return 2;
    if (ch == '+' || ch == '-')
        return 1;
    else
        return 0;
}

int main()
{
    int n;

    cin >> n;

    while (n--) {
        string exp, cha;
        stack<char> pol;
        stack<int> cal;

        cin >> exp;
        for (int i = 0; i < exp.size() - 1; i++) {
            if ('0' <= exp[i] && exp[i] <= '9') {
                while (true) {
                    cha.push_back(exp[i]);
                    if ('0' > exp[i + 1] || exp[i + 1] > '9') {
                        cha.push_back('.');
                        break;
                    }
                    else
                        i++;
                }
            }
            else if (exp[i] == '(')
                pol.push(exp[i]);
            else if (exp[i] == ')') {
                while (true) {
                    if (pol.top() == '(') {
                        pol.pop();
                        break;
                    }
                    cha.push_back(pol.top());
                    pol.pop();

                }
            }
            else {
                while (!pol.empty()) {
                    if (pri(exp[i]) < pri(pol.top())) {
                        cha.push_back(pol.top());
                        pol.pop();
                    }
                    else 
                        break;
                }
                pol.push(exp[i]);
            }
        }

        while (!pol.empty()) {
            cha.push_back(pol.top());
            pol.pop();
        }

        for (int i = 0; i < cha.size(); i++) {
            if ('0' <= cha[i] && cha[i] <= '9') {
                int tmp = cha[i] - '0';

                while (true) {
                    i++;
                    if (cha[i] == '.') 
                        break;
                    tmp *= 10;
                    tmp += cha[i] - '0';
                }
                cal.push(tmp);
            }
            else {
                int a, b;

                b = cal.top();
                cal.pop();
                a = cal.top();
                cal.pop();

                if (cha[i] == '*') 
                    cal.push(a * b);
                else if (cha[i] == '/') 
                    cal.push(a / b);
                else if (cha[i] == '+') 
                    cal.push(a + b);
                else if (cha[i] == '-') 
                    cal.push(a - b);
            }
        }
        cout << cal.top() << endl;
    }

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<24)

bool isNum(char ch){return ('0'<=ch&&ch<='9');}

struct calcStr{
  string s;
  int pos,len;
  bool flag;
  void init(){ pos=0;len=s.size(); flag=false; }

  int head2Num(){
    int res=0;
    while(pos<len){
      if(isNum(s[pos])){
	res*=10;
	res+=(s[pos]-'0');
	pos++;
      }else break;
    }
    return res;
  }
  
  int getNum(){
    if(s[pos]=='('){
      pos++;
      return getAns();
    }
    int res=head2Num();
    if(pos==len)return res;
    else if(s[pos]=='*'){
      pos++;
      return res*getNum();
    }else if(s[pos]=='/'){
      pos++;
      return res/getNum();
    }
    return res;
  }
  
  int getAns(){
    int res=getNum(),num;
    while(1){
      if(pos==len)break;
      if(s[pos]==')'){pos++;break;}
      char ch=s[pos++];
      num=getNum();
      if(ch=='+')res+=num;
      else if(ch=='-')res-=num;
    }
    if(flag)return INF;
    else return res;
  }
};

int main(){
  int Tc;cin>>Tc;
  calcStr a;
  while(Tc--){
    cin>>a.s;
    a.s=a.s.substr(0,a.s.size()-1);
    a.init();
    cout<<a.getAns()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double EPS = 1e-10;

typedef string::const_iterator State;

int express(State& p);
int factor(State& p);
int term(State &p);
int number(State &p);

// 足し算
int express(State& p) {
	int r = term(p);
	
	for(;;) {
		if(*p == '+') {
			p++;
			int rs = term(p);
			r += rs;
		}
		else if(*p == '-') {
			p++;
			int rs = term(p);
			r -= rs;
		}
		else {
			break;
		}
	}
	
	return r;
}


// 掛け算
int term(State &p) {
	int r = factor(p);
	
	for(;;) {
		if(*p == '*') {
			p++;
			int rs = factor(p);
			r *= rs;
		}
		else if(*p == '/') {
			p++;
			int rs = factor(p);
			r /= rs;
		}
		else {
			break;
		}
	}
	
	return r;
}

// カッコ
int factor(State &p) {
	if(*p == '(') {
		p++;
		int ret = express(p);
		p++;
		return ret;
	}
	return number(p);
}

int number(State &p) {
	// if(*p == '(') return factor(p);
	int ret = 0;
	
	while(isdigit(*p)) {
		ret *= 10;
		ret += *p - '0';
		p++;
	}
	
	return ret;
}

int main() {
	int N; cin >> N;
	cin.ignore();
	while(N--) {
		string line;
		getline(cin, line);
		State p = line.begin();
		int ans = express(p);
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int prior[128];

int parse(string s)
{
	if(s[0]=='(' && s[s.length()-1]==')')
		return parse(s.substr(1,s.length()-2));

	int divprr=3,divpos=10000000;
	for(int i=0,d=0;i<s.length();i++){
		if     (s[i]=='(')	d++;
		else if(s[i]==')')	d--;

		if(d==0 && prior[s[i]]!=0){
			if(divprr>prior[s[i]])
				divprr=prior[s[i]],divpos=i;
		}
	}

	if(divpos==10000000)	return atoi(s.c_str());

	switch(s[divpos]){
		case '+': return parse(s.substr(0,divpos)) + parse(s.substr(divpos+1));
		case '-': return parse(s.substr(0,divpos)) - parse(s.substr(divpos+1));
		case '*': return parse(s.substr(0,divpos)) * parse(s.substr(divpos+1));
		case '/': return parse(s.substr(0,divpos)) / parse(s.substr(divpos+1));
	}
}

int main()
{
	prior['+']=prior['-']=1;
	prior['*']=prior['/']=2;

	int n;	cin>>n;
	while(n--){
		string s;	cin>>s;
		s=s.substr(0,s.length()-1);
		cout<<parse(s)<<endl;
	}

	return 0;
}