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 <vector>
#include <stack>
using namespace std;


#define REP(i,x)for(int i=0;i<(int)x;i++)

// 逆ポーランド記法
// op!=0なら演算子
struct Parsed{
	char op;
	int value;
	int priority;
};
vector<Parsed> parse(const string &s){
	int op[256] = {}; // 演算子の情報
	// 演算子の情報を入れる
	op['+']=op['-']=2;
	op['*']=op['/']=3;
	op['(']=100;
	op[')']=1;
	stack<Parsed> stack;
	vector<Parsed> res;
	int it=0;
	while(it<(int)s.size()){
		int pri=0,value=0,opd=0;
		if(op[(int)s[it]]){
			pri=op[(int)s[it]];
			value=0;
			opd=s[it];
		}else{
			value=0;
			while(it<(int)s.size()&&isdigit(s[it])){
				value=value*10+s[it]-'0';
				it++;
			}
			it--;
			pri=99;
		}
		while(!stack.empty()&&pri<=stack.top().priority&&stack.top().op != '('){
			res.push_back(stack.top());
			stack.pop();
		}
		if(opd!=')'){
			stack.push((Parsed){opd,value,pri});
		}else{
			stack.pop();
		}
		it++;
	}
	while(!stack.empty()){
		res.push_back(stack.top());
		stack.pop();
	}
	return res;
}
int main() {
	string in;
	for(cin>>in;cin>>in;){
		in=in.substr(0,in.size()-1);
		vector<Parsed> parsed = parse(in);
		stack<int> stack;
		for(int i=0;i<(int)parsed.size();i++){
			if(parsed[i].op=='+'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(a+b);
			}else if(parsed[i].op=='-'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(b-a);
			}else if(parsed[i].op=='*'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(a*b);
			}else if(parsed[i].op=='/'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(b/a);
			}else{
				stack.push(parsed[i].value);
			}
		}
		cout<<stack.top()<<endl;
	}
	return 0;
}

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

string S;

int expr(int& p);
int term(int& p);
int factor(int& p);
int number(int& p);

int expr(int& p) {
    int v1 = term(p); 
    while(S[p] == '+' || S[p] == '-') {
        char op = S[p];
        p++;
        int v2 = term(p); 
        if(op == '+') {
            v1 += v2;
        } else {
            v1 -= v2;
        }
    }
    return v1;
}

int term(int& p) {
    int v1 = factor(p);
    while(S[p] == '*' || S[p] == '/') {
        char op = S[p];
        p++;
        int v2 = factor(p);
        if(op == '*') {
            v1 *= v2;
        } else {
            v1 /= v2;
        }
    }
    return v1;
}

int factor(int& p) {
    if(isdigit(S[p])) {
        return number(p);
    }

    p++;
    int res = expr(p);
    p++;
    return res;
}

int number(int& p) {
    int res = 0;
    while(isdigit(S[p])) {
        res *= 10;
        res += S[p] - '0';
        ++p;
    }
    return res;
}


int main() {
    int n;
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> S;
        int p = 0;
        cout << expr(p) << endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

stack<int> DigitStack;
stack<char> OpStack;
string Formulation;

void calculation() {
	int num2, result;
	char ch;

	ch = OpStack.top();
	OpStack.pop();
	switch (ch)
	{
	case '+': 
		num2 = DigitStack.top();
		DigitStack.pop();
		result = DigitStack.top();
		DigitStack.pop();
		result += num2; 
		break;
	case '-': 
		num2 = DigitStack.top();
		DigitStack.pop();
		result = DigitStack.top();
		DigitStack.pop(); 
		result -= num2; 
		break;
	case '*':
		num2 = DigitStack.top();
		DigitStack.pop();
		result = DigitStack.top();
		DigitStack.pop();
		result *= num2; 
		break;
	case '/': 
		num2 = DigitStack.top();
		DigitStack.pop();
		result = DigitStack.top();
		DigitStack.pop();
		result /= num2; break;
	default:return;
	}
	DigitStack.push(result);
}

int calculateNumber(int *pIndex) {
	int sum;
	string tmp;
	stringstream ss;

	tmp += Formulation[(*pIndex)++];
	while (isdigit(Formulation[*pIndex])) {
		tmp += Formulation[*pIndex];
		(*pIndex)++;
	}
	//cout << tmp << endl;
	ss << tmp;
	ss >> sum;
	ss.clear();
	(*pIndex)--;

	return sum;
}

int priorityOfOperator(char ch)
{
	switch (ch)
	{
	case '(':
		return 3;
	case '*':
	case '/':
		return 2;
	case '+':
	case '-':
		return 1;
	default:
		return 0;
	}
}

void solve() {
	int i, num, len;
	char cTmp;

	len = Formulation.size() - 1;
	for (i = 0; i < len; i++) {
		cTmp = Formulation[i];
		
		if (isdigit(cTmp)) {
			num = calculateNumber(&i);
			DigitStack.push(num);
			continue;
		}

		if ( cTmp == '(' || OpStack.empty() || OpStack.top() == '(' ) {
			OpStack.push(cTmp);
			continue;
		}

	    if (priorityOfOperator(cTmp) > priorityOfOperator(OpStack.top())) {
			OpStack.push(cTmp);
		}		
		else {
			do {
				calculation();
			} while ( !OpStack.empty() && OpStack.top() != '(' && priorityOfOperator(cTmp) <= priorityOfOperator(OpStack.top()));

			if (cTmp == ')') {
				OpStack.pop();
			}
			else {
				OpStack.push(cTmp);
			}
		}
	}

	while (!OpStack.empty()) {
		calculation();
	}

}

int main() {
	int n, result;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> Formulation;
		//cout << Formulation << endl;
		solve();
		result = DigitStack.top();
		DigitStack.pop();
		cout << result << endl;
	}

	return 0;
}

C++: #include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14


int expr(const char **);
int term(const char **);
int factor(const char **);
int number(const char **);

int expr(const char **p) {
  int val = term(p);
  while (1) {
    if (**p == '+') {
      (*p)++;
      val += term(p);
    } else if (**p == '-') {
      (*p)++;
      val -= term(p);
    } else {
      break;
    }
  }
  return val;
}

int term(const char **p) {
  int val = factor(p);
  while (1) {
    if (**p == '*') {
      (*p)++;
      val *= factor(p);
    } else if (**p == '/') {
      (*p)++;
      val /= factor(p);
    } else {
      break;
    }
  }
  return val;
}

int factor(const char **p) {
  if (**p == '(') {
    (*p)++;
    int val = expr(p);
    (*p)++;
    return val;
  }
  return number(p);
}

int number(const char **p) {
  int val = 0;
  while ('0' <= **p && **p <= '9') {
    val = val * 10 + **p - '0';
    (*p)++;
  }
  return val;
}

signed main() {
  int n;
  scanf("%d", &n);
  char s[101];
  while (n--) {
    scanf("%s", s);
    const char *p = s;
    printf("%d\n", expr(&p));
  }
}

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

int calc(int l,int r)
{
	int pa=0;
	for(int i = r; i >= l; --i)
	{
		if(in[i]==')') pa++;
		else if(in[i]=='(') pa--;
		else if(!pa)
		{
			if(in[i]=='+') return calc(l,i-1)+calc(i+1,r);
			if(in[i]=='-') return calc(l,i-1)-calc(i+1,r);
		}
	}
	pa=0;
	for(int i = r; i >= l; --i)
	{
		if(in[i]==')') pa++;
		else if(in[i]=='(') pa--;
		else if(!pa)
		{
			if(in[i]=='*') return calc(l,i-1)*calc(i+1,r);
			if(in[i]=='/') return calc(l,i-1)/calc(i+1,r);
		}
	}
	
	if(in[l]=='('&&in[r]==')') return calc(l+1,r-1);

	stringstream ss(in.substr(l,r-l+1));
	int res; ss>>res;
	return res;
}


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