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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int calc(char *s, int &i, bool f = false){
  int ret = 0;
  bool flag = i >= 0 && s[i-1] == '(';
  
  for(;s[i];){
    
    if(s[i] == ')'){
      if(flag) i++;
      return ret;
    }
    
    if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/'){

      i++;
      
      if(s[i] == '('){
        i++;

        if(i-2 < 0) ret += calc(s,i);
        else if(s[i-2] == '+') ret += calc(s,i,false);
        else if(s[i-2] == '-') ret -= calc(s,i,false);
        else if(s[i-2] == '*') ret *= calc(s,i,false);
        else if(s[i-2] == '/') ret /= calc(s,i,false);

        continue;
      }
      
      if(s[i-1] == '+') ret += calc(s,i,true);
      else if(s[i-1] == '-') ret -= calc(s,i,true);
      
    }else{
      int start = i-1;
      int sum = 0;
      
      while(!(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/' || s[i] == '\0' || s[i] == ')')){
        sum *= 10;
        sum += s[i] - '0';
        i++;
      }
      /*
      debug(ret);
      debug(sum);
      debug(s[start]);
      */
      
      if(start < 0){
        ret += sum;
      }else{
        if(s[start] == '(') ret += sum;
        if(s[start] == '+') ret += sum;
        if(s[start] == '-') ret += sum;
        if(s[start] == '*') ret *= sum;
        if(s[start] == '/') ret /= sum;
      }
      
      if(f && (s[i] == '+' || s[i] == '-')){
        //debug(i);
        //debug(s[i]);
        return ret;
      }
      
      //debug(ret);
    }
  }

  //debug(s[i]);
  //debug(ret);
  
  return ret;
}


int main(){
  char s[SIZE];
  int t = 0;

  int n;

  scanf("%d",&n);

  while(n--){
    char s2[SIZE] = {};
    t = 0;
    scanf("%s",s);

    s[strlen(s)-1] = '\0';
    strcat(s2,"0+");
    strcat(s2,s);

    string str = s2;
    int r = 0;

    while((r = (int)str.find("((")) != -1){
      str.replace(r, 2, "(0+(");
    }

    sprintf(s2,"%s",str.c_str());
    
    printf("%d\n",calc(s2,t));
  }
  
  return 0;
}

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

string str;

int subj(int s, int e){
	int n = 0;
	for(int i = s;i < e;i++){
		if(str[i] == '(')n++;
		if(str[i] == ')'){if(n == 0)return i;n--;}
	}
}

int calc(int s, int e, int m, int z){
	int p = 0;
	for(p = s;p < e && str[p] >= '0' && str[p] <= '9';p++);
	int a = atoi(str.substr(s, p-s).c_str());
	if(str[s] == '('){
		p = subj(s+1, e);
		a = calc(s+1, p, 0, 0);p++;
		//cout << "p = " << s << p << " ";
	}
	if(m == 1)a *= z;
	if(m == 2)a = z / a;
	
	if(str[p] == '+')return a + calc(p+1, e, 0, 0);
	if(str[p] == '-')return a - calc(p+1, e, 0, 0);
	if(str[p] == '*')return calc(p+1, e, 1, a);
	if(str[p] == '/')return calc(p+1, e, 2, a);
	if(str[p] == '=' || str[p] == ')')return a;
	
	return 0;
}

int main(){
	int n;cin >> n;
	while(n--){
		cin >> str;
		cout << calc(0, str.size(), 0, 0) << endl;
	}
	
	return 0;
}

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

int cur;
string s;

int digit() {
	return ( s[cur++] - '0' );
}

int number() {
	int n = digit();
	while ( isdigit( s[cur] ) )
		n = n * 10 + digit();
	return n;
}

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

int term() {
	int n = factor();
	while ( s[cur] == '*' || s[cur] == '/' ) {
		cur++;
		if ( s[cur - 1] == '*' )
			n *= factor();
		else
			n /= factor();
	}
	return n;
}

int expression() {
	int n = term();
	while ( s[cur] == '+' || s[cur] == '-' ) {
		cur++;
		if ( s[cur - 1] == '+' )
			n += term();
		else
			n -= term();
	}
	return n;
}

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cur = 0;
		cin >> s;
		int m = expression();
		cout << m << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>

using namespace std;

char siki[200];
int cur;


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

int number(){
  int n=digit();
  while(cur<strlen(siki) && isdigit(siki[cur]))
    n=n*10+digit();

  return n;
}

int factor();

int term(){
  int a=factor();
  while(cur<strlen(siki) && (siki[cur]=='*' || siki[cur]=='/')){
    char op=siki[cur];
    ++cur;
    int b=factor();
    if(op=='*')a*=b;else a/=b;
  }
  return a;
}

int expression(){
  int a=term();
  while(cur<strlen(siki) && (siki[cur]=='+' || siki[cur]=='-')){
    char op=siki[cur];
    cur++;
    int b=term();
    if(op=='+')a+=b;else a-=b;
  }
  return a;
}

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

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

  for(int i=0;i<n;i++){
    cin>>siki;
    cur=0;
    cout<<expression()<<endl;
  }
}

C++: #include<iostream>
#include<cctype>
#include<string>
using namespace std;
typedef string::const_iterator State;
class ParseError{};

int expression(State &);
int term(State &);
int factor(State &);
int number(State &);

int main(void){
  int N;
  cin >> N;
  cin.ignore();

  for(int i=0;i<N;i++){
    string s;
    getline(cin,s);

    State begin=s.begin();
    int ans=expression(begin);
    cout << ans << endl;
  }
  return 0;
}

int expression(State &begin){
  int ret=term(begin);

  while(1){
    if(*begin=='+'){
      begin++;
      ret+=term(begin);
    }
    else if(*begin=='-'){
      begin++;
      ret-=term(begin);
    }
    else break;
  }
  return ret;
}

int term(State &begin){
  int ret=number(begin);

  while(1){
    if(*begin=='*'){
      begin++;
      ret*=factor(begin);
    }
    else if(*begin=='/'){
      begin++;
      ret/=factor(begin);
    }
    else break;
  }
  return ret;
}

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

int number(State &begin){
  int ret=0;

  while(isdigit(*begin)){
    ret*=10;
    ret+=*begin-'0';
    begin++;
  }
  return ret;
}