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 <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>

using namespace std;

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

vector<string> toReversePorland(string str){

  vector<string> hand;
  vector<string> side;
  
  for(int i = 0; i < str.size(); i++){
    if(str[i] == ' ')
      continue;
    else if(str[i] == '=')
      break;
    if(str[i] >= '0' && str[i] <= '9'){
      string num;
      while(i < str.size()){
	if(str[i] < '0' || str[i] > '9'){
	  break;
	}
	num += str[i];
	i++;
      }
      hand.push_back(num);
      i--;
    }
    else if(str[i] == '('){
      string tmp;
      tmp += str[i];
      side.push_back(tmp);
    }
    else if(str[i] == ')'){
      // ツ右ツ環古環づ慊づ可可算ツ子ツづーツ暗ェツづつつクツづつ偲ィツ個ウツづ可姪淞つキ
      for(int j = side.size()-1 ; ;j--){
	if(side[j] == "("){
	  if(j != 0){
	    vector<string> tmp;
	    for(int k = 0; k < j; k++){
	      tmp.push_back(side[k]);
	    }
	    side = tmp;
	  }
	  else
	    side.clear();
	  break;
	}
	else{
	  string tmp = side[j];
	  hand.push_back(tmp);
	}
      }
    }
    else{
      if(side.size() == 0){
	string tmp;
	tmp += str[i];
	side.push_back(tmp);
      }
      else{
	char cs = side[side.size()-1][0];
	if(cs != '+' && cs != '-' && cs != '*' && cs != '/'){
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
	else{
	  if(getPriority(str[i]) < getPriority(cs)){
	    hand.push_back(side[side.size()-1]);
	    string tmp;
	    tmp += str[i];
	    side[side.size()-1] = tmp;
	  }
	  else{
	    string tmp;
	    tmp += str[i];
	    side.push_back(tmp);
	  }
	}
      }
      
      // else if(str[i] == '+' || str[i] == '-'){
      // 	if(side[side.size()-1] == "*" || side[side.size()-1] == "/"){
      // 	  hand.push_back(side[side.size()-1]);
      // 	  string tmp;
      // 	  tmp += str[i];
      // 	  side[side.size()-1] = tmp;
      // 	}
      // 	else{
      // 	  string tmp;
      // 	  tmp += str[i];
      // 	  side.push_back(tmp);
      // 	}
      // }
      // else{
      // 	if(side[side.size()-1] == "*" || side[side.size()-1] == "/"){
      // 	  hand.push_back(side[side.size()-1]);
      // 	  string tmp;
      // 	  tmp += str[i];
      // 	  side[side.size()-1] = string(tmp);
      // 	}
      // 	else{
      // 	  string tmp;
      // 	  tmp += str[i];
      // 	  side.push_back(tmp);
      // 	}
      // }
    }
  }

  for(int i = side.size()-1; i >= 0; i--){
    hand.push_back(string(side[i]));
  }
  
  return hand;
}


int calc(vector<string> str){
  stack<int> st;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == "+" || str[i] == "-" || str[i] == "*" || str[i] == "/"){
      int val[2];
      val[0] = st.top();
      st.pop();
      val[1] = st.top();
      st.pop();
      if(str[i] == "+"){
	st.push(val[0] + val[1]);
      }
      if(str[i] == "-"){
	st.push(val[1] - val[0]);
      }
      if(str[i] == "*"){
	st.push(val[0] * val[1]);
      }
      if(str[i] == "/"){
	st.push(val[1] / val[0]);
      }
    }
    else{
      st.push(atoi(str[i].c_str()));
    }
  }
  return st.top();
}

int main(){

  int n;
  string s;
  //  getline(cin,s);
  //  n = atoi(s.c_str());
  cin >> n;
    //  scanf("%d\n",&n);
  
  vector<string> input;
  string str;
  for(int i = 0; i < n; i++){
    //  getline(cin,str);
    cin >> str;
    input.push_back(str);
  }

  for(int i = 0; i < n; i++){
    str = input[i];
    // vector<string> vec = toReversePorland(str);
    // for(int i = 0; i < vec.size(); i++)
    //   cout << vec[i] << endl;
    cout << calc(toReversePorland(str)) << endl;
  }
  
  return 0;
}

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

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

int main(void){
  int N;
  cin >> N;
  cin.ignore();

  for(int i=0;i<N;i++){
    string s;
    getline(cin,s);

    State begin=s.begin();
    ll ans=expression(begin);
    cout << ans << endl;
  }
  return 0;
}

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

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

ll term(State &begin){
  ll ret=number(begin);

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

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

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

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

C++: #include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
string s;
int index;
int number();
int factor();
int term();
int expr();
int number(){
    int n = s[index] - '0';
    index++;
    while(isdigit(s[index])){
        n = n*10 + s[index] - '0';
        index++;
    }
    return n;
}
int factor(){
    if(isdigit(s[index])) return number();
    index++;
    int ret = expr();
    index++;
    return ret;
}
int term(){
    int val = factor();
    while(s[index] == '*' || s[index] == '/'){
        char op = s[index];
        index++;
        int tmp = factor();
        if(op == '*') val *= tmp;
        else val /= tmp;
    }
    return val;
}
int expr(){
    int val = term();
    while(s[index] == '+' || s[index] == '-'){
        char op = s[index];
        index++;
        int tmp = term();
        if(op == '+')val += tmp;
        else val -= tmp;
    }
    return val;
}
int main(){
    int N;
    cin >> N;
    while(N--){
        index = 0;
        cin >> s;
        s.resize(s.size()-1);
        cout << expr() << "\n";
    }
    return 0;
}

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

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


int expr(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 = term(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);

  // ここで構文が正しければ s[i] == '(' となる
  i++; // '('を読み飛ばす
  int ret = expr(s, i);
  i++; // ')'を読み飛ばす
  return ret;
}

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


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