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++: #ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);

bool f;

int expression(string s,int& p){
  int res=term(s,p);
  while(p<(int)s.size()){
    if(s[p]=='+'){
      p++;
      res+=term(s,p);
      continue;
    }
    if(s[p]=='-'){
      p++;
      res-=term(s,p);
      continue;
    }
    break;
  }
  return res;
}

int term(string s,int& p){
  int res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='*'){
      p++;
      res*=factor(s,p);
      continue;
    }
    if(s[p]=='/'){
      p++;
      int tmp=factor(s,p);
      if(tmp==0){
        f=1;
        break;
      }
      res/=tmp;
      continue;
    }
    break;
  }
  return res;
}

int factor(string s,int& p){
  int res;
  if(s[p]=='('){
    p++;
    res=expression(s,p);
    p++;
  }else{
    res=number(s,p);
  }
  return res;
}

int number(string s,int& p){
  int res=0;
  while(p<(int)s.size()&&isdigit(s[p]))
    res=res*10+s[p++]-'0';
  return res;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    int p=0;
    cin>>s;s.pop_back();
    cout<<expression(s,p)<<endl;
  }
  return 0;
}

/*
  verified on 2017/11/20
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=0109
*/
#endif

C++: #include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int calc(string s){
    while(1){
        vector<pair<int, int>> vv;
        int depth = 0;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == '('){
                vv.push_back(pair<int, int>(i, ++depth));
            }else if(s[i] == ')'){
                --depth;
            }
        }
        if(vv.size() != 0){
            sort(vv.begin(), vv.end(), [](auto a, auto b){return a.second != b.second ? a.second > b.second : a.first < b.first;});
            int pos;
            for(pos = vv[0].first; s[pos] != ')'; pos++);
            int ret = calc(s.substr(vv[0].first + 1, pos - vv[0].first - 1));
            string t = s.substr(0, vv[0].first) + to_string(ret) + s.substr(pos + 1);
            s = t;
        }else{
            while(1){
                map<char, vector<int>> m;
                for(int i = 0; i < s.size(); i++){
                    if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') m[s[i]].push_back(i);
                }
                vector<int> v;
                if(m.find('*') != m.end() || m.find('/') != m.end()){
                    for(int pos : m['*']) v.push_back(pos);
                    for(int pos : m['/']) v.push_back(pos);
                }else{
                    for(int pos : m['+']) v.push_back(pos);
                    for(int pos : m['-']) v.push_back(pos);
                }
                if(v.size() == 0 || (v.size() == 1 && v[0] == 0)) break;
                sort(v.begin(), v.end());
                string t;
                int pos = v[0];
                string num[2];
                int tmp;
                for(int j = pos - 1; 0 <= j; j--){
                    if('0' <= s[j] && s[j] <= '9'){
                        num[0] += s[j];
                    }else{
                        for(int k = 0; k <= j; k++){
                            t += s[k];
                        }
                        break;
                    }
                }
                for(int j = pos + 1; j <= s.size(); j++){
                    if('0' <= s[j] && s[j] <= '9'){
                        num[1] += s[j];
                    }else{
                        tmp = j;
                        break;
                    }
                }
                int add;
                switch(s[pos]){
                    case '+':
                        add = stoi(num[0]) + stoi(num[1]);
                        break;
                    case '-':
                        add = stoi(num[0]) - stoi(num[1]);
                        break;
                    case '*':
                        add = stoi(num[0]) * stoi(num[1]);
                        break;
                    case '/':
                        add = stoi(num[0]) / stoi(num[1]);
                        break;
                }
                t += to_string(add);
                for(int j = tmp; j < s.size(); j++) t += s[j];
                s = t;
            }
            return stoi(s);
        }
    }
}
    
int main(){
    int N;
    cin >> N;
    for(int pomu = 0; pomu < N; pomu++){
        string s;
        cin >> s;
        s = s.substr(0, s.size() - 1);
        cout << calc(s) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<ll,const char*> parsed;

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

parsed expr(const char* s)
{
	//cout<<"expr(\""<<s<<"\")"<<endl;
	parsed now=term(s);
	while(*now.second=='+' || *now.second=='-'){
		char op=*now.second;
		parsed next=term(now.second+1);
		if(op=='+')
			now=parsed(now.first+next.first,next.second);
		else
			now=parsed(now.first-next.first,next.second);
	}
	//cout<<"expr(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed term(const char* s)
{
	//cout<<"term(\""<<s<<"\")"<<endl;
	parsed now=fact(s);
	while(*now.second=='*' || *now.second=='/'){
		char op=*now.second;
		parsed next=fact(now.second+1);
		if(op=='*')
			now=parsed(now.first*next.first,next.second);
		else
			now=parsed(now.first/next.first,next.second);
	}
	//cout<<"term(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed fact(const char* s)
{
	//cout<<"fact(\""<<s<<"\")"<<endl;
	//if(s[0]=='('){
	//	parsed res=expr(s+1);
	//	res.second++;
	//	return res;
	//}
	//else{
	//	const char* p=s;
	//	if(*p=='-')
	//		p++;
	//	ll n=0;
	//	while(isdigit(*p)){
	//		n=n*10+*p-'0';
	//		p++;
	//	}
	//	return parsed(n,p);
	//}
	
	if(s[0]=='-' || isdigit(s[0])){
		const char* p=s;
		if(*p=='-')
			p++;
		ll n=0;
		while(isdigit(*p)){
			n=n*10+(*p-'0');
			p++;
		}
		return parsed(n,p);
	}
	//else if(s[0]=='('){
	//	parsed res=expr(s+1);
	//	res.second++;
	//	return res;
	//}
	//else
	//	exit(0);
	else{
		parsed res=expr(s+1);
		res.second++;
		return res;
	}
}

int main()
{
	int n;
	cin>>n;
	rep(i,n){
		string s;
		cin>>s;
		cout<<expr(s.c_str()).first<<endl;
	}
	//string s;
	//getline(cin,s);
	//while(getline(cin,s))
	//	cout<<expr(s.c_str()).first<<endl;
	
	return 0;
}