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

int exp();
int term();
int factor();
int number();
int digit();

string str;

int p,len,val;

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

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

int factor(){
  int val;
  if( str[p] == '(' ){
      p++;
      val =  exp();
      p++;
  }else{
    val = number();
  }

  return val;
}

int number(){
  int val = 0;
  while( digit() ){
    int num = str[p] - '0';
    val = val * 10 + num;
    p++;
  }
  return val;
}

int digit(){
  if( str[p] == '1' || str[p] == '2' || str[p] == '3' || str[p] == '4' ||
      str[p] == '5' || str[p] == '6' || str[p] == '7' || str[p] == '8' ||
      str[p] == '9' || str[p] == '0' ) return 1;
  return 0;
}

  
int main(){
  int n; cin >> n;
  
  for(int i = 0; i < n; i++ ){
    p = 0;
    cin >> str;
    
    int ans = exp();      
    
    cout << ans << endl;
    
  }
  
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

vector<string> split(string delim,string str){
	vector<string> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find_first_of(delim) != string::npos){
				//cout << str.substr(i,j) << endl;
				if(str.substr(i,j-1).size() > 0 ) res.push_back(str.substr(i,j-1));
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

string calc(vector<string> v){
	stack<string> stk;
	for(int i=0;i<v.size();i++){
		if(v[i]=="-"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2-num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="+"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2+num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="*"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2*num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="/"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2/num1);
			res = buf;
			
			stk.push(res);
		}
		else{
			stk.push(v[i]);
		}
	}
	return stk.top();
}

vector<string> rvs_polish(string str){
	stack<string> stk;
	vector<string> v;

	string tmp="";
	vector<string> res;
	if(str[0]=='-'){
		str='0'+str;
	}
	for(int i=0;i<str.size();i++){
		if(str[i]=='*'){
			v.push_back(tmp);
			v.push_back("*");
			tmp="";
		}

		else if(str[i]=='/'){
			v.push_back(tmp);
			v.push_back("/");
			tmp="";
		}

		else if(str[i]=='-' && (str[i-1]=='*' || str[i-1]=='/')){
			tmp+='-';
		}

		else if(str[i]=='-' && (str[i-1]!='*' && str[i-1]!='/')){
			v.push_back(tmp);
			v.push_back("-");			
			tmp="";
		}

		else if(str[i]=='+'){
			v.push_back(tmp);
			v.push_back("+");			
			tmp="";
		}
		else if(str[i]=='='){
			v.push_back(tmp);
			v.push_back("=");			
			tmp="";
		}

		else{
			tmp+=str.substr(i,1);
		}
	}

	v.push_back(tmp);

	for(int i=0;i<v.size();i++){
		if(v[i]=="*"){
			if(stk.empty()){
				stk.push("*");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+"){
					stk.push("*");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("*");
				}
			}
		}

		else if(v[i]=="/"){
			if(stk.empty()){
				stk.push("/");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+" || opr == "*"){
					stk.push("/");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("/");
				}
			}
		}

		else if(v[i]=="-"){
			if(stk.empty()){
				stk.push("-");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("-");
			}
		}
		else if(v[i]=="+"){
			if(stk.empty()){
				stk.push("+");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("+");
			}
		}
		else{
			res.push_back(v[i]);
		}
	}

	while(!stk.empty()){
		res.push_back(stk.top());
		stk.pop();
	}

	return res;
}

void dfs(string str){
	stack<P> stk;
	for(int i=0;i<str.size();i++){
		if(str[i]=='(') {stk.push(P('(',i));}
		else if(str[i]==')') {
			char sym = stk.top().first;
			if(sym != '(') continue;

			int pos = stk.top().second;
			stk.pop();

			if(str.substr(pos+1,(i-1)-(pos+1)+1).find('(') == string::npos
				&& str.substr(pos+1,(i-1)-(pos+1)+1).find(')') == string::npos){
					vector<string> pol = rvs_polish(str.substr(pos+1,(i-1)-(pos+1)+1));
					string num = calc(pol);
					str.replace(pos,i-pos+1,num);
					//cout << str << endl;
					while(!stk.empty()) stk.pop();
					i=-1;
					continue;
			}
		}
	}

	vector<string> ans = rvs_polish(str);

	cout << calc(ans) << endl;
}

int main(){
	string str;
	while(getline(cin,str)){
		int n;
		sscanf(str.c_str(),"%d",&n);
		for(int i=0;i<n;i++){
			getline(cin,str);
			dfs(str.substr(0,str.size()-1));
		}
	}
}

C++: #include <stdio.h>

char formula[101];
int p;

int additive() {
  int result = multitive();
  while (formula[p] == '+' || formula[p] == '-')
    if (formula[p++] == '+')
      result += multitive();
    else
      result -= multitive();
  return result;
}

int multitive() {
  int result = term();
  while (formula[p] == '*' || formula[p] == '/')
    if (formula[p++] == '*')
      result *= term();
    else
      result /= term();
  return result;
}

int term() {
  int result = 0;
  if (formula[p] == '(') {
    p++;
    result = additive();
    p++;
  } else while ('0' <= formula[p] && formula[p] <= '9')
    result = result * 10 + formula[p++] - '0';
  return result;
}

int main() {
  int i, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", formula);
    p = 0;
    printf("%d\n", additive());
  }
  return 0;
}