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

int cal1();
int cal2();
int cal3();

int index;
string s;

int getNum(){
	int n = 0;
	for (; '0' <= s[index] && s[index] <= '9'; index++) n = n * 10 + s[index] - '0';
	return n;
}

int cal1(){
	int ret = cal2();
	while (1){
		if (s[index] == '+') {
			index++;
			ret += cal2();
		}
		else if (s[index] == '-') {
			index++;
			ret -= cal2();
		}
		else return ret;
	}
}

int cal2(){
	int ret = cal3();
	while (1){
		if (s[index] == '*') {
			index++;
			ret *= cal3();
		}
		else if (s[index] == '/') {
			index++;
			ret /= cal3();
		}
		else return ret;
	}
}

int cal3(){
	int ret = 0;
	int old = index;
	if (s[index] == '('){
		index++;
		ret = cal1();
		index++;
	}
	else {
		ret = getNum();
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++){
		index = 0;
		getline(cin, s);
		s.pop_back();
		cout << cal1() << endl;
	}
	return 0;
}

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

int p;
string exp;

int term();
int expression();
int factor();


int expression(){
     int value;
	 value=term();
	 while(exp[p]=='+' || exp[p]=='-'){
		 if(exp[p]=='+'){
			 p++;
			 value+=term();
		 }
		 else{
			 p++;
			 value-=term();
		 }
	 }
	 return value;
}


int term(){
	int value;
	value=factor();
	while(exp[p]=='*' || exp[p]=='/'){
		if(exp[p]=='*'){
			p++;
			value*=factor();
		}
		else{
			p++;
			value/=factor();
		}
	}

	return value;
}

int factor(){
	int value=0;
	if(exp[p]=='('){
		value=expression();
	}
	else{
		while(isdigit(exp[p])){
			value=value*10+exp[p++]-'0';
		}
	}
	return value;
}



int main()
{
	int i,c;
	cin>>c;
	for(i=0;i<c;i++){
		cin>>exp;
		p=0;
		cout<<expression()<<"\n";
		}
	cout<<"\n";
	return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
 
int calc_E(char line[101],int left,int right);
int calc_T(char line[101],int left,int right);
int calc_F(char line[101],int left,int right);
int calc_NUM(char line[101],int left,int right);
 
 
int calc_E(char line[101],int left,int right){
 
    int depth = 0;
    queue<int> Q;
 
    //深さ0の、プラスまたは-を探す
    for(int i = left; i <= right; ){
        if(line[i] == '(')depth++;
        else if(line[i] == ')')depth--;
 
        if(depth != 0){
            i++;
        }else if(line[i] != '+' && line[i] != '-'){
            i++;
        }else{
            if(line[i] == '+'){
                Q.push(i);
                i++;
            }else{ //line[i] == '-'
                if((i != left) && ((line[i-1] >= '0' && line[i-1] <= '9') || line[i-1] == ')')){ //-は、depthが0でもnegの場合あり
                    Q.push(i);
                }
                while(i <=right && line[i] == '-')i++; //negの-が続いている場合があるので、読み飛ばす
            }
        }
    }
 
    if(Q.empty()){ //深さ0の+-がない
        return calc_T(line,left,right);
    }
 
    int tmp = calc_E(line,left,Q.front()-1),tmp_right;
 
    if(tmp == BIG_NUM)return BIG_NUM;
 
    while(!Q.empty()){
        int loc = Q.front();
        Q.pop();
 
        if(Q.empty()){
            tmp_right = calc_T(line,loc+1,right);
        }else{
            tmp_right = calc_T(line,loc+1,Q.front()-1);
        }
 
        if(tmp_right == BIG_NUM){
            return BIG_NUM;
        }
 
        if(line[loc] == '+'){
            tmp += tmp_right;
        }else{
            tmp -= tmp_right;
        }
    }
 
    return tmp;
}
 
int calc_T(char line[101],int left,int right){
 
    int depth = 0;
    queue<int> Q;
 
    //深さ0の、*,/を探す
    for(int i = left; i <= right; ){
        if(line[i] == '(')depth++;
        else if(line[i] == ')')depth--;
 
        if(depth != 0){
            i++;
        }else if(line[i] != '*' && line[i] != '/'){
            i++;
        }else{
            Q.push(i);
            i++;
        }
    }
 
    if(Q.empty()){ //深さ0の*がない
        return calc_F(line,left,right);
    }
 
    int tmp = calc_T(line,left,Q.front()-1),tmp_right;
 
    if(tmp == BIG_NUM)return BIG_NUM;
 
    while(!Q.empty()){
        int loc = Q.front();
        Q.pop();
 
        if(Q.empty()){
            tmp_right = calc_F(line,loc+1,right);
        }else{
            tmp_right = calc_F(line,loc+1,Q.front()-1);
        }
 
        if(tmp_right == BIG_NUM){
            return BIG_NUM;
        }
 
        if(line[loc] == '*'){
            tmp *= tmp_right;
        }else{
            tmp /= tmp_right;
        }
    }
    return tmp;
}
 
int calc_F(char line[101],int left,int right){
 
    if(line[left] >= '0' && line[left] <= '9'){
        return calc_NUM(line,left,right);
    }else if(line[left] == '-'){
        return -1*calc_F(line,left+1,right);
    }else if(line[left] == '('){
 
        int depth = 0;
        int close_pos = BIG_NUM;
 
        for(int i = left; i <= right; i++){
            if(line[i] == '(')depth++;
            else if(line[i] == ')'){
                depth--;
                if(depth == 0){
                    close_pos = i;
                    break;
                }
            }
        }
 
        if(close_pos == BIG_NUM || close_pos != right)return BIG_NUM;
 
        return calc_E(line,left+1,close_pos-1);
    }else{
        return BIG_NUM;
    }
}
 
int calc_NUM(char line[101],int left,int right){
 
    int ret = 0;
    for(int i = left; i <= right; i++){
        ret = 10*ret+line[i]-'0';
    }
    return ret;
}
 
 
int main(){
 
    int N,length;
    char buf[101];
 
    scanf("%d",&N);
 
    for(int loop = 0; loop < N; loop++){
        scanf("%s",buf);
        for(length = 0; buf[length] != '='; length++);
 
        printf("%d\n",calc_E(buf,0,length-1));
    }
 
    return 0;
}

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

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

struct calcStr{
  string s;
  int pos,len;

  void init(){ pos=0;len=s.size();}

  int head2Num(){
    bool f=false;
    if(s[pos]=='-'){f=true;pos++;}
    int res=0;
    while(pos<len){
      if(isNum(s[pos])){
	res*=10;
	res+=(s[pos]-'0');
	pos++;
      }else break;
    }
    if(f)res*=-1;
    return res;
  }
  
  int getNum(){
    int res;
    if(s[pos]=='('){
      pos++;
      res = getAns();
    }else res=head2Num();

    if(s[pos]=='*'){
      pos++;
      return res*getNum();
    }else if(s[pos]=='/'){
      pos++;
      return res/getNum();
    }else{
      return res;
    }
  }
  
  int getAns(){
    int res=getNum(),num;
    while(1){
      if(s[pos]==')'){pos++;break;}
      if(s[pos]=='=')break;
      char ch=s[pos++];
      num=getNum();
      if(ch=='+')res+=num;
      else if(ch=='-')res-=num;
      else assert(0);
    }
    return res;
  }
};

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