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 <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct State{
  int result,backpos;
  State(int a,int b){
    result=a;
    backpos=b;
  }
};

bool is_numchar(char c){
  if('1'<=c&&c<='9') return true;
  if(c=='0') return true;
  return false;
}

int strtoint(std::string s){
  int result=0;
  for(int i=0;i<s.size();i++){
    result+=(s[i]-'0')*(int)std::pow(10,s.size()-1-i);
  }
  return result;
}



State expr(const std::string& s,int frontpos);
State factor(const std::string& s,int frontpos);
State term(const std::string& s,int frontpos);
State number(const std::string& s,int frontpos);

State expr(const std::string& s,int frontpos){
  State state=term(s,frontpos);
  while(1){
    int op_pos=state.backpos+1;
    if(op_pos<s.size()&&s[op_pos]=='+'){
      State new_state=term(s,op_pos+1);
      state.result+=new_state.result;
      state.backpos=new_state.backpos;
    }else if(op_pos<s.size()&&s[op_pos]=='-') {
      State new_state = term(s, op_pos + 1);
      state.result -= new_state.result;
      state.backpos = new_state.backpos;
    }else break;
  }
  return state;
}

State term(const std::string& s,int frontpos){
  State state=factor(s,frontpos);
  while(1){
    int op_pos=state.backpos+1;
    if(op_pos<s.size()&&s[op_pos]=='*'){
      State new_state=factor(s,op_pos+1);
      state.result*=new_state.result;
      state.backpos=new_state.backpos;
    }else if(op_pos<s.size()&&s[op_pos]=='/') {
      State new_state = factor(s, op_pos + 1);
      state.result /= new_state.result;
      state.backpos = new_state.backpos;
    }else break;
  }
  return state;
}

State factor(const std::string& s,int frontpos){
  if(s[frontpos]=='('){
    State result=expr(s,frontpos+1);
    result.backpos++;// ')'を読み飛ばす
    return result;
  }else{
    return number(s,frontpos);
  }
}

State number(const std::string& s,int frontpos){
  int result;
  int backpos=frontpos;
  std::string numstr;
  for(int i=frontpos;i<s.size();i++){
    if(is_numchar(s[i])){
      numstr+=s[i];
      backpos++;
    }else {
      backpos--;
      break;
    }
  }
  result=strtoint(numstr);
  return State(result,backpos);
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    std::string s;
    cin>>s;
    std::string throw_s;
    for(int j=0;j<s.size()-1;j++){
      throw_s+=s[j];
    }
    cout<<expr(throw_s,0).result<<endl;

  }





  



  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);

bool f;

int expression(string s,int& p){
  int res=term(s,p);
  while(p<(int)s.size()){
    if(s[p]=='+'){
      p++;
      res+=term(s,p);
      continue;
    }
    if(s[p]=='-'){
      p++;
      res-=term(s,p);
      continue;
    }
    break;
  }
  return res;
}

int term(string s,int& p){
  int res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='*'){
      p++;
      res*=factor(s,p);
      continue;
    }
    if(s[p]=='/'){
      p++;
      int tmp=factor(s,p);
      if(tmp==0){
	f=1;
	break;
      }
      res/=tmp;
      continue;
    }
    break;
  }
  return res;
}

int factor(string s,int& p){
  int res;
  if(s[p]=='('){
    p++;
    res=expression(s,p);
    p++;
  }else{
    res=number(s,p);
  }
  return res;
}

int number(string s,int& p){
  int res=0;
  while(p<(int)s.size()&&isdigit(s[p]))
    res=res*10+s[p++]-'0';
  return res;
}

signed main(){
  string s;
  while(cin>>s){
    int p=0;
    cin>>s;
    if(s.back()=='=') s.pop_back();
    cout<<expression(s,p)<<endl;
  }
  return 0;
}

/*
verified on 2017/04/26
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=0109
*/

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

void calc(string st, stack<ll> &s) {	
	if(st == "*") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(a * b);
	} else if(st == "+") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(a + b);
	} else if(st == "-") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(b - a);
	} else if(st == "/") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(b / a);
	} else {
		s.push(atoi(st.c_str()));
	}
}
int getPriority(string s) {
	if(s == "(") {
		return 5;
	} else if(s == "*" || s == "/") {
		return 3;
	} else if(s == "+" || s == "-") {
		return 2;
	} else if(s == ")") { 
		return 1;
	} else return 4;
}

int main() {
	int n;
	cin >> n;
	while(n--) {
		string str;
		cin >> str;
		str.erase(--str.end());
		
		vector<string> v;
		
		int f = 0;
		rep(i, str.size()) {			
			if(isdigit(str[i])) {
				f++;
			} else {
				if(f) {
					string st;
					rep(j,f) {
						st += str[i - f + j];
					}
					v.push_back(st);
					string st2;
					st2 += str[i];
					v.push_back(st2);
					f = 0;
				} else {
					string st3;
					st3 += str[i];
					v.push_back(st3);
				}
			}
		}
		if(f) {
			string st;
			rep(j,f) {
				st += str[str.size() - f + j];
			}
			v.push_back(st);
		}

		stack<string> s;
		vector<string> nv;
		stack<ll> ret;
		int p = 0;
		rep(i,v.size()) {
			p = getPriority(v[i]);
			while(!s.empty() && getPriority(s.top()) > p && s.top() != "(") {
				nv.push_back(s.top());
				s.pop();
			}
			if(v[i] == ")") {
				s.pop();
			} else {
				s.push(v[i]);
			}
		}
		while(!s.empty()) {
			nv.push_back(s.top());
			s.pop();
		}
		rep(i,nv.size()) {
			calc(nv[i], ret);
		}
		cout << ret.top() << endl;
	}
	return 0;
}