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 <sstream>
using namespace std;

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


string foo2(string s){
	// cout<<"foo2 "<<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;
			if(xr<s.size()-1) ss2<<s.substr(xr+1);
			
			string tmp;
			ss2>>tmp;
			// cout<<"foo2 "<<s<<" "<<endl;
			return foo2(tmp);
		}
	}
	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;
			if(xr<s.size()-1) ss2<<s.substr(xr+1);
			string tmp;
			ss2>>tmp;
			return foo2(tmp);
		}
	}
	return s;
}

string foo1(string s){
	// cout<<s<<endl;
	// string tmp="123456";
	// cout<<tmp.substr(5)<<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){
		// if(xr>=s.size()-1) return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1));
		if(xr==s.size()-1) return foo1(s.substr(0,xl)+foo2(s.substr(xl+1,xr-xl-1)));
		// return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1)+s.substr(xr+1));
		return foo1(s.substr(0,xl)+foo2(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;
		// cout<<s.substr(0,0)<<endl;
		s=s.substr(0,s.size()-1);
		s=solve(s);
		cout<<s<<endl;
	}
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

P equation(const string &str, int pos=0);
P factor(const string &str, int pos = 0);
P term(const string &str, int pos = 0);

P equation(const string &str, int pos){
	P res = factor(str,pos);
	while(str[res.second] == '+'){
		P res_ = factor(str,res.second+1);
		res.first += res_.first;
		res.second = res_.second;
	}

	while(str[res.second] == '-'){
		P res_ = factor(str,res.second+1);
		res.first -= res_.first;
		res.second = res_.second;
	}
	return res;
}

P factor(const string &str, int pos) {
	P res = term(str, pos);
	while (str[res.second] == '*') {
		P res_ = term(str, res.second+1);
		res.first *= res_.first;
		res.second = res_.second;
	}

	while (str[res.second] == '/') {
		P res_ = term(str, res.second+1);
		res.first /= res_.first;
		res.second = res_.second;
	}
	return res;
}

P term(const string &str, int pos) {
	if(str[pos] == '('){
		P res = equation(str,pos+1);
		res.second += 1;
		return res;
	} else {
		int val = 0;
		while(isdigit(str[pos])){
			val = val * 10 + (str[pos++]-'0');
		}
		return P(val,pos);
	}
}


int main(){
	string str;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>str;
		P res = equation(str);
		cout << res.first << endl;
	}
}

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

int exp(char* & p);

int num(char* & p) {
    int ret = 0;
    while (isdigit(*p)) {
        ret *= 10;
        ret += *p - '0';
        p++;
    }
    return ret;
}

int fac(char* & p) {
    int ret = 0;
    if (*p == '(') {
        p++;
        ret += exp(p);
        p++;
    } else {
        ret += num(p);
    }
    return ret;
}

int term(char* & p) {
    int ret = fac(p);
    while(1) {
        if (*p == '*') {
            p++;
            ret *= fac(p);
        } else if (*p == '/') {
            p++;
            ret /= fac(p);
        } else {
            break;
        }
    }
    return ret;
}

int exp(char* & p) {
    int ret = term(p);
    while(1) {
        if (*p == '+') {
            p++;
            ret += term(p);
        } else if (*p == '-') {
            p++;
            ret -= term(p);
        } else break;
    }
    return ret;
}

int eval(const string & s){
    char* p = (char*)s.c_str();
    return exp(p);
}

int eval(const char* str){
    char* p = (char*)str;
    return exp(p);
}

using namespace std;

int main(){
    char str[128];
    while(gets(str))
        cout << eval(str) << endl;
    return 0;
}

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

int calc1();
int calc2();
int calc3();

int p;
string eq;

int calc1() {
  int a = calc2();
  if (eq[p]=='+') {
    p++;
    a += calc2();
  } else if (eq[p]=='-') {
    p++;
    a -= calc2();
  }
  return a;
}

int calc2() {
  int a = calc3();
  if (eq[p]=='*') {
    p++;
    a *= calc3();
  } else if (eq[p]=='/') {
    p++;
    a /= calc3();
  }
  return a;
}

int calc3() {
  int a;
  if (eq[p]=='(') {
    p++;
    a = calc1();
    p++;
  } else {
    a = 0;
    while (eq[p]>='0'&&eq[p]<='9') {
      a *= 10;
      a += eq[p++] - '0';
    }
  }
  return a;
}

int main() {
  int n, r;

  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> eq;
    p = 0;
    r = calc1();
    cout << r << endl;
  }
}