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

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


string foo2(string s){
	// cout<<s<<endl;
	bool f=true;
	rep(i,s.size()){
		if(i==0){
			if(s[0]=='-');
			else f=false;
		}
		else{
			if(s[i]>='0'&&s[i]<='9'){

			}
			else{
				f=false;
			}
		}
	}
	if(f) return s;
	// bool f=false;
	rep(i,s.size()){
		if(s[i]=='*'||s[i]=='/'){
			int xl=i,xr=i;
			f=true;
			while(1){
				if(xl==0) break;
				else if(s[xl-1]>='0'&&s[xl-1]<='9'){
					xl--;
				}
				else{
					
					break;
				}
			}
			while(1){
				if(xr==s.size()-1) break;
				else if(s[xr+1]>='0'&&s[xr+1]<='9'){
					xr++;
				}
				else{
					
					break;
				}
			}
			stringstream ss1,ss2;
			// cout<<s.substr(xl,xr-xl+1)<<endl;
			ss1<<s.substr(xl,xr-xl+1);
			int a,b;
			char t;
			ss1>>a;
			// cout<<"a "<<a<<endl;
			ss1>>t;
			ss1>>b;
			ss2<<s.substr(0,xl);
			int tt;
			if(t=='*'){
				tt=a*b;
			}
			else{
				tt=a/b;
			}
			ss2<<tt;
			ss2<<s.substr(xr+1);
			ss2>>s;
			// cout<<"foo2 "<<s<<" "<<endl;
			return foo2(s);
		}
	}
	rep(i,s.size()){
		if(s[i]=='+'||s[i]=='-'){
			int xl=i,xr=i;
			f=true;
			while(1){
				if(xl==0) break;
				else if(s[xl-1]>='0'&&s[xl-1]<='9'){
					xl--;
				}
				else{
					break;
				}
			}
			while(1){
				if(xr==s.size()-1) break;
				else if(s[xr+1]>='0'&&s[xr+1]<='9'){
					xr++;
				}
				else{
					break;
				}
			}
			stringstream ss1,ss2;
			ss1<<s.substr(xl,xr-xl+1);
			int a,b;
			char t;
			ss1>>a;
			ss1>>t;
			ss1>>b;
			ss2<<s.substr(0,xl);
			int tt;
			if(t=='+'){
				tt=a+b;
			}
			else{
				tt=a-b;
				// cout<<tt<<endl;
			}
			ss2<<tt;
			ss2<<s.substr(xr+1);
			ss2>>s;
			return foo2(s);
		}
	}
	return s;
}

string foo1(string s){
	// cout<<s<<endl;
	int xl=-1,xr=-1;
	rep(i,s.size()){
		if(s[i]=='('){
			xl=i;
		}
		else if(s[i]==')'){
			xr=i;
			break;
		}
	}
	if(xr!=-1){
		return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1)+s.substr(xr+1));
	}
	return foo2(s);
}

string solve(string s){
	return foo1(s);
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		s=s.substr(0,s.size()-1);
		s=solve(s);
		cout<<s<<endl;
	}
}

C++: #include<string>
#include<iostream>
#include<cctype>
using namespace std;
typedef string::const_iterator State;

int number(State &begin) {
  int ans = 0;
  bool flag = false;
  if (*begin == '-') flag = true, begin++;
  while (isdigit(*begin)) ans = ans * 10 + (*begin - '0'), begin++;
  if (flag) ans = -ans;
  return ans;
}

int expression(State &begin);

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

int term(State &begin) {
  int ans = factor(begin);
  while (1) {
    if (*begin == '*') begin++, ans *= factor(begin);
    else if (*begin == '/') begin++, ans /= factor(begin);
    else return ans;
    //begin++;
  }
}

int expression(State &begin) {
  int ans = term(begin);
  while (1) {
    if (*begin == '+') begin++, ans += term(begin);
    else if (*begin == '-') begin++, ans -= term(begin);
    else return ans;
    //begin++;
  }
}

int main() {
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    State temp = s.begin();
    cout << expression(temp) << endl;
  }
}

C++: import re
class c:
	def __str__(self):
		return str(self.x)
	def __init__(self,value):
		self.x=value
	def __add__(self,value):
		return c(self.x+value.x)
	def __sub__(self,value):
		return c(self.x-value.x)
	def __mul__(self,value):
		return c(self.x*value.x)
	def __truediv__(self,value):
		return c(int(self.x/value.x))
n=int(input())
for i in range(n):
	s=input()[:-1]
	s=re.sub(r'(\d+)',r'c(\1)',s)
	print(eval(s))

C++: #include<iostream>
#include<string>
#include<cmath>
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 = floor(*tmp * val);
	else if(c == '/' && val != 0) *tmp = floor(*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 <bits/stdc++.h>
using namespace std;
typedef long long ll;

string s;
int N;
int c;

int expr();
int term();
int factor();
int num();

void debug(string text){
	return;
	cout << text + " ";
	for(int i = 0; i < N; i++){
		if(i == c) cout << '[' << s[i] << ']';
		else cout << s[i];
	}
	cout << endl;
}

int expr(){
	debug("expr");
	int x = term();
	while(c < N && (s[c] == '+' || s[c] == '-')){
		if(s[c] == '+'){
			c++;
			x += term();
		}
		else{
			c++;
			x -= term();
		}
	}
	return x;
}

int term(){
	debug("term");

	int x = factor();
	while(c < N && (s[c] == '*' || s[c] == '/')){
		if(s[c] == '*'){
			c++;
			x *= factor();
		}
		else{
			c++;
			x /= factor();
		}
	}
	return x;
}

int factor(){
	debug("factor");

	if(s[c] == '('){
		c++;
		int ret = expr();
		assert(s[c] == ')');
		c++;
		return ret;
	}
	return num();
}

int num(){
	debug("num");

	int ret = 0;
	while(c < N && isdigit(s[c])){
		ret = ret * 10 + s[c] - '0';
		c++;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int n;
	cin >> n;
	while(n--){
		cin >> s;
		s.pop_back();
		N = s.size();
		c = 0;
		cout << expr() << endl;
	}
}

C++: #include <iostream>

int main()
{
std::cout << std::endl;
return 0;
}