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 <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int expr();
int term();
int fact();

char buf[101];
int p;

int expr()
{
	int v = term();
	while (buf[p] == '+' || buf[p] == '-')
	{
		if (buf[p] == '+')
		{
			p++;
			v += term();
		} else {
			p++;
			v -= term();
		}
	}
	return v;
}

int term()
{
	int v = fact();
	while (buf[p] == '*' || buf[p] == '/')
	{
		if (buf[p] == '*')
		{
			p++;
			v *= fact();
		} else {
			p++;
			v /= fact();
		}
	}
	return v;
}

int fact()
{
	int v = 0;
	if (buf[p] == '(')
	{
		p++;
		v = expr();
		p++;
	} else {
		while (isdigit(buf[p]))
		{
			v = v * 10 + buf[p] - '0';
			p++;
		}
	}
	return v;
}


int main()
{
	int times, ans;
	
	cin >> times;
	rep(i, times)
	{
		cin >> buf;
		p = 0;
		ans = expr();
		cout << ans << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

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

bool is_digit(char c){return '0' <= c && c <= '9';}
string i2s(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

string parse(int i, string s) {
  //cout<<s<<endl;
  bool flag = true;
  
  // brace
  if (s.find('(') != -1) {
    // æª©ç`FbNµÄA')'Éoï¤êÆ
    // »¤ÅÈ¢êÉª¯é
    bool mode = true;
    REP(j,s.find('(')+1, s.size()) {
      if (s[j] == ')') break;
      if (s[j] == '(') {
        mode = false;
        break;
      }
    }
    // ÊÌÊuðæ¾·é
    int lbr = s.find('('), rbr;
    if (mode) {
      rbr = s.find(')');
    } else {
      for(int j=s.size()-1;j>=0;j--) if (s[j] == ')') {
        rbr = j; break;
      }
    }
    // ÊàÌvZðæÉs¤½ßÉssð¾é
    string inner = parse(0, s.substr(lbr+1, rbr-lbr-1));
    // ÊàðÁ·é
    s.erase(lbr, rbr-lbr+1);
    s.insert(lbr, inner);
    return parse(0, s);
  }
  
  rep(i,s.size()) if (s[i] == '*' || s[i] == '/') {
    int lhs, rhs, res;
    int li = i-1, ri = i+1;
    while (is_digit(s[li]) && li >= 0) li--;
    while (is_digit(s[ri]) && ri < s.size()) ri++;
    lhs = atoi(s.substr(li+1, i-1-li).c_str());
    rhs = atoi(s.substr(i+1, ri-1-i).c_str());
    
    if (lhs == 0 || rhs == 0) {
      res = 0;
    } else {
      if (s[i] == '*') {
        res = lhs * rhs;
      } else {
        res = lhs / rhs;
      }
    }
    
    s.erase(li+1, ri-li-1);
    s.insert(li+1, i2s(res));
    flag = false;
    return parse(0, s);
  }
  
  rep(i,s.size()) if (s[i] == '+' || s[i] == '-') {
    if (s[i] == '-' && i == 0) continue; 
    int lhs, rhs, res;
    int li = i-1, ri = i+1;
    while (is_digit(s[li]) && li >= 0) li--;
    while (is_digit(s[ri]) && ri < s.size()) ri++;
    lhs = atoi(s.substr(li+1, i-1-li).c_str());
    rhs = atoi(s.substr(i+1, ri-1-i).c_str());
    if (s[i] == '+') {
      res = lhs + rhs;
    } else {
      res = lhs - rhs;
    }
    s.erase(li+1, ri-li-1);
    s.insert(li+1, i2s(res));
    flag = false;
    return parse(0, s);
  }
  
  return s;
}

void solve() {
  string s; cin>>s;
  s = s.substr(0, s.size()-1);
  cout<<parse(0, s)<<endl;
}

int main (int argc, char const* argv[]) {
  int n; cin>>n;
  rep(i,n) solve();
  return 0;
}

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(){
    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(){
    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]==')'||s[pos]=='='){pos++;break;}
      char ch=s[pos++];
      num=getNum();
      if(ch=='+')res+=num;
      else if(ch=='-')res-=num;
    }
    return res;
  }
};

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

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

typedef pair<int,int> result;
#define value first
#define p second

result equation(const string &s, int p = 0);
result factor(const string &s, int p=0);
result term(const string &s, int p=0);

result equation(const string &s,int p) {
    result r = factor(s,p);
    while(s[r.p] == '+' || s[r.p] == '-') {
        result r_ = factor(s, r.p+1);
        if(s[r.p] == '+') r.value += r_.value;
        else r.value -= r_.value;
        r.p = r_.p;
    }
    return r;
}

result factor(const string &s, int p) {
    result r = term(s,p);
    while(s[r.p] == '*' || s[r.p] == '/') {
        result r_ = term(s, r.p+1);
        if(s[r.p] == '*') r.value *= r_.value;
        else r.value /= r_.value;
        r.p = r_.p;
    }
    return r;
}

result term(const string &s, int p) {
    if(s[p] == '(') {
        result r = equation(s,p+1);
        r.p += 1;
        return r;
    }else{
        int value = 0;
        while(isdigit(s[p]))
            value = value*10 + (s[p++] - '0');
        return result(value,p);
    }
}

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

    string s;
    for(int i=0; i<n; ++i) {
        cin>>s;
        result r = equation(s);
        cout<<r.value<<endl;
    }
}