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 <bits/stdc++.h>

using namespace std;

long long int calc(string ex){
	long long int str,cnt,ans=0,now=0,addn=1,addd=1,n=ex.length(),i;
	bool sus=false,minus=false;
	char pm='+',md='*';
	for(i=0; i<n; i++){
		if(sus){
			if(ex[i]=='('){
				cnt++;
			}else if(ex[i]==')'){
				cnt--;
				now = calc(ex.substr(str,i-str));
				sus = false;
			}
		}else{
			switch(ex[i]){
				case '(':
					str = i+1;
					cnt = 1;
					sus = true;
					break;
				case '-':
					if(i==0 || ex[i-1]== '+' || ex[i-1]== '-' || ex[i-1]== '*' || ex[i-1]== '/'){
						minus = true;
						break;
					}
				case '+':
					if(minus){
						now *= -1;
						minus = false;
					}
					if(md == '*'){
						addn *= now;
					}else{
						addd *= now;
					}
					if(pm == '+'){
						ans += addn/addd;
					}else{
						ans -= addn/addd;
					}
					pm = ex[i];
					md = '*';
					now = 0;
					addn = 1;
					addd = 1;
					break;
				case '*':
				case '/':
					if(minus){
						now *= -1;
						minus = false;
					}
					if(md == '*'){
						addn *= now;
					}else{
						addd *= now;
					}
					md = ex[i];
					now = 0;
					break;
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					now *= 10;
					now += ex[i]-'0';
					break;
				default:
					break;
			}
		}
	}
	if(minus){
		now *= -1;
		minus = false;
	}
	if(md == '*'){
		addn *= now;
	}else{
		addd *= now;
	}
	if(pm == '+'){
		ans += addn/addd;
	}else{
		ans -= addn/addd;
	}
	return ans;
}

int main(void){
	int n,i;
	long long int ans;
	string str;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> str;
		ans = calc(str);
		cout << ans << endl;
	}
	return 0;
}

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

int exp(string &s, int &i);
int term(string &s, int &i);
int factor(string &s, int &i);
int number(string &s, int &i);

int exp(string &s, int &i)
{
  int val = term(s, i);
  while(s[i] == '+' || s[i] == '-'){
    char op = s[i];
    i++;
    int val2 = term(s, i);
    if(op == '+') val += val2;
    else val -= val2;
  }
  return val;
}

int term(string &s, int &i)
{
  int val = factor(s, i);
  while(s[i] == '*' || s[i] == '/'){
    char op = s[i];
    i++;
    int val2 = factor(s, i);
    if(op == '*') val *= val2;
    else val /= val2;
  }
  return val;
}

int factor(string &s, int &i)
{
  if(isdigit(s[i]))
    return number(s, i);
  i++;
  int val = exp(s, i);
  i++;
  return val;
}

int number(string &s, int &i)
{
  int n = s[i] - '0';
  i++;
  while(isdigit(s[i])){
    n = n * 10 + (s[i] - '0');
    i++;
  }
  return n;
}

int main()
{
  int n;
  cin >> n;
  for(int j = 0; j < n; j++){
    string s;
    cin >> s;
    int i = 0;
    cout << exp(s, i) << endl;
  }
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define INF 0x7FFFFFFF
#define ll long long

ll expr();
ll term();
ll fac();
int left();
char peek();
char pop();
int isdeg(char z);
int isdeg(char z);
void eat(char z);
ll num();

string s;
int t;

int main(){
  int n;
  cin >> n;
  cin >> s;
  while(n){
    long long ans=0;
    t=0;
    s.pop_back();
    ans=expr();
    n--;
    cout << ans << endl;
    cin >> s;
  }
}


ll expr(){
  ll res=term();
  while(left()&&(peek()=='+'||peek()=='-')){
    if(peek()=='+'){
      eat('+');
      res+=term();
    }
    else if(peek()=='-'){
      eat('-');
      res-=term();
    }
  }
  return res;
}

ll term(){
  ll res=fac();
  while(left()&&(peek()=='*'||peek()=='/')){
    if(peek()=='*'){
      eat('*');
      res*=fac();
    }
    else if(peek()=='/'){
      eat('/');
      res/=fac();
    }
  }
  return res;
}

ll fac(){
  if(peek()=='('){
    eat('(');
    ll res=expr();
    eat(')');
    return res;
  }
  else{
    return num();
  }
}


int left(){                 //まだ文字列が残っているかを調べる
  return int(s.size())>t;
}

char peek(){                //次の文字を一文字先読みする
  return s[t];
}

char pop(){                 //次の文字を読みとって、インデックスを進める
  t++;
  return s[t-1];
}

int isdeg(char z){
  return z>='0'&&z<='9';
}

void eat(char z){
  if(s[t]!=z) cout << "warning " << t << endl;
  t++;
}

ll num(){
  ll res=0;
  while(left()&&isdeg(peek())){
    res*=10;
    res+=pop()-'0';
  }
  return res;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;
int p;

int exp(string str);
int term(string str);
int fact(string str);

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

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

int fact(string str)
{
	int val = 0;
	if(str[p] == '('){
		p++;
		val = exp(str);
		p++;
	} else {
		string s = "";
		while('0' <= str[p] && str[p] <= '9'){
			s += str[p++];
		}
		if(s.size() > 0){
			val = atoi(s.c_str());
		}
	}
	
	return val;
}

int main()
{
	int n;
	string str;
	
	while(cin >> n && n){
		while(n--){
			cin >> str;
			p = 0;
			cout << exp(str) << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef string::const_iterator State;

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

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 = factor(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;
}

int main() {
	int n;
	cin >> n;
	cin.ignore();
	while (n--){
		string s;
		getline(cin,s);
		State begin = s.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}

    return 0;
}