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 <string>
#include <cctype>
#include <iostream>
typedef std::string::const_iterator State;
class ParseError {};

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

int main(void){
	int N;
	std::cin >> N;
	std::cin.ignore();
	for(int i = 0; i < N; ++i){
		std::string s;
		std::getline(std::cin, s);
		State begin = s.begin();
		s[s.size()-1]='\0';
		int ans = expression(begin);
		std::cout << ans << std::endl;
	}
	return 0;
}

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

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

	return ret;
}

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

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

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

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

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
using namespace std;
#define rep(p,q) for(int i = p;i < q; i++)
#define big (long long int)(10e9 + 7)

int siki(string &str, int &i);
int kou(string &str, int &i);
int insu(string &str, int &i);
int number(string &str, int &i);

int main(void) {
	int num = 0;
	cin >> num;
	rep(0, num) {
		string str;
		int x = 0;
		cin >> str;
		cout << siki(str, x) << endl;
	}
}

int siki(string &str,int &i) {
	int val1 = kou(str,i);
	if (str[i] == '+' || str[i] == '-') {
		char op = str[i];
		i++;
		int val2 = kou(str, i);
		if (op == '+') {
			val1 = val1 + val2;
		}
		else
		{
			val1 = val1 - val2;
		}
	}
	return val1;
}

int kou(string &str, int &i) {
	int val1 = insu(str, i);
	if (str[i] == '*' || str[i] == '/') {
		char op = str[i];
		i++;
		int val2 = insu(str, i);
		if (op == '*') {
			val1 = val1 * val2;
		}
		else {
			val1 = val1 / val2;
		}
	}
	return val1;
}

int insu(string &str, int &i) {
	int val1 = 0;
	if(str[i] != '(')val1 = number(str, i);
	else if(str[i] == '(') {
		i++;
		val1 += siki(str, i);
		i += 1;
	}
	return val1;
}

int number(string &str, int &i) {
	int val1 = 0;
	int val2 = 0;
	if (str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' || str[i] == '4' || str[i] == '5' || str[i] == '6' || str[i] == '7' || str[i] == '8' || str[i] == '9') {
			 val1 = (int)str[i] - (int)'0';
		i++;
		if ( str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' || str[i] == '4' || str[i] == '5' || str[i] == '6' || str[i] == '7' || str[i] == '8' || str[i] == '9') {
			int now = i;
			val2 += number(str, i);
			val1 = val1 * pow(10,i - now);
			val1 += val2;

		}
	}
	return val1;
}

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

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

using namespace std;
pair<int64_t,int> expr(const string &s, int i);

pair<int64_t,int> num(const string &s, int i) {
  int64_t v = 0;
  while(i < s.size() && ('0' <= s[i] && s[i] <= '9')) {
    v *= 10;
    v += s[i] - '0';
    ++i;
  }
  return make_pair(v, i);
}

pair<int64_t,int> factor(const string &s, int i) {
  if (s[i] == '(') {
    auto p = expr(s, i+1);
    ++p.second;
    return p;
  } else {
    return num(s, i);
  }
}
pair<int64_t,int> term(const string &s, int i) {
  int64_t val;
  tie(val, i) = factor(s, i);
  while(i < s.size() && (s[i] == '*' || s[i] == '/')) {
    int64_t val2;
    int j;
    tie(val2, j) = factor(s, i+1);
    if (s[i] == '*') val *= val2;
    else val /= val2;
    i = j;
  }
  return make_pair(val, i);
}

pair<int64_t,int> expr(const string &s, int i) {
  int64_t val;
  tie(val, i) = term(s, i);
  while(s[i] == '+' || s[i] == '-') {
    int64_t val2;
    int j;
    tie(val2, j) = term(s, i+1);
    if (s[i] == '+') val += val2;
    else val -= val2;
    i = j;
  }
  return make_pair(val, i);
}

int main() {
  int n;
  cin>>n;
  REP(ds,n) {
    string s;
    cin>>s;
    cout << expr(s, 0).first << endl;
  }
  return 0;
}

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

void select_cal(char c, int *tmp, int val){

	if(c == '+') *tmp += val;
	else if(c == '-') *tmp -= val;
	else if(c == '*') *tmp *= val;
	else if(c == '/') *tmp /= val;

}

int calculation(string str, int len, int begin){

	int ans, tmp, cnt;
	char c;
	
	ans = 0;
	tmp = 0;
	c = '+';

	for(int i=begin; i<len; i++){
		if(str[i] == '+' || str[i] == '-'){
			ans += tmp;
			tmp = 0;
			c = str[i];
		}
		else if(str[i] == '*' || str[i] == '/'){
			c = str[i];
		}
		else if(str[i] == '('){
			select_cal(c, &tmp, calculation(str, len, i+1));
			cnt = 1;
			do{
				i++;
				if(str[i] == '(') cnt++;
				else if(str[i] == ')') cnt--;
			}while(cnt != 0);
		}
		else if(str[i] == ')' || str[i] == '='){
			break;
		}
		else {
			select_cal(c, &tmp, str[i] - '0');
		}
	}
	ans += tmp;

	return ans;

}

int main(){

	int n;
	string str;
	
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> str;
		cout << calculation(str, str.length(), 0) << endl;
	}

	return 0;

}

C++: #include <string>
#include <vector>
#include <iostream>
using namespace std;
string S; int n, junjo[4] = { 0, 0, 1, 1 };
long long calc(int L,int R){
    int K=0;
    vector<int>junjo2[4];
    for(int i=0;i<4;i++){
        junjo2[junjo[i]].push_back(i);
    }
    for(int i=0;i<4;i++){
        if(junjo2[i].size()>=1){
            for(int j=R-1;j>=L;j--){
                if(S[j]=='('){K++;}
                if(S[j]==')'){K--;}
                for(int k=0;k<junjo2[i].size();k++){
                    if(junjo2[i][k]==0){
                        if(S[j]=='+' && K==0){
                            return calc(L,j)+calc(j+1,R);
                        }
                    }
                    if(junjo2[i][k]==1){
                        if(S[j]=='-' && K==0){
                            return calc(L,j)-calc(j+1,R);
                        }
                    }
                    if(junjo2[i][k]==2){
                        if(S[j]=='*' && K==0){
                            return calc(L,j)*calc(j+1,R);
                        }
                    }
                    if(junjo2[i][k]==3){
                        if(S[j]=='/' && K==0){
                            return calc(L,j)/calc(j+1,R);
                        }
                    }
                }
            }
        }
    }
    if(S[L]=='(' && S[R-1]==')'){return calc(L+1,R-1);}
    return stoi(S.substr(L,R-L));
}
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) cin >> S, printf("%d\n", calc(0, S.size() - 1));
	return 0;
}