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;

class calc{
  string s;
  string::iterator it;
public:
  calc(string str){
    s = str;
    it = str.begin();
  }

  int fact(){
    if(*it == '('){
      *it++;
      int ret = exp();
      *it++;
      return ret;
    } else {
      int ret = 0;
      while('0' <= *it && *it <= '9'){
	ret *= 10;
	ret += *it-'0';
	++it;
      }
      return ret; 
    }
}

  int turm(){
    int ret = fact();
    while(*it == '*' || *it == '/'){
      if(*it == '*'){
	*it++;
	ret *= fact();
 
      } else if(*it == '/'){
	*it++;
	ret /= fact(); 
      }
    }
    return ret;
  }
  int exp(){
    int ret = turm();
    while(*it == '+' || *it == '-'){
      if(*it == '+'){
	*it++;
	ret += turm();
 
      } else if(*it == '-'){
	*it++;
	ret -= turm(); 
      }
    }
    return ret;
  }
};

int main(){
  int n;
  cin >> n;
  while(n--){
    string str;
    cin >> str;
    calc ans(str);
    cout << ans.exp() << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int calc(char *s, char *end)
{
	/*for (char *p = s; p != end; p++) printf("%c", *p);
	puts("");*/
	
	bool f = false;
	
	vector<int> st;
	vector<char> op;
	
	char *p = s;
	while (p != end){
		if (!f) if (*p == '('){
			char *e = p + 1;
			int cnt = 1;
			while (true){
				if (*e == '(') cnt++;
				if (*e == ')') cnt--;
				if (cnt == 0) break;
				e++;
			}
			st.push_back(calc(p + 1, e));
			p = e;
		}
		if (f) if (*p == '+' || *p == '-' || *p == '*' || *p == '/'){
			op.push_back(*p);
			p++;
			f ^= 1;
			continue;
		}
		if (!f) if (*p >= '0' && *p <= '9'){
			int n = atoi(p);
			st.push_back(n);
			stringstream ss;
			ss << n;
			p += ss.str().size() - 1;
		}
		if (!f) if (*p == '-'){
			int n = atoi(p);
			st.push_back(n);
			stringstream ss;
			ss << n;
			p += ss.str().size() - 1;
			//printf("%s\n", ss.str().c_str());
		}
		if (op.size() && (op.back() == '*' || op.back() == '/')){
			int b = st.back(); st.pop_back();
			int a = st.back(); st.pop_back();
			if (op.back() == '*') a *= b;
			if (op.back() == '/') a /= b;
			st.push_back(a);
			op.pop_back();
		}
		p++;
		f = !f;
		/*printf("__");
		for (auto a : st) printf("%d ", a);
		puts("");*/
	}
	
	while (op.size()){
		int t = st.front(); st.erase(st.begin());
		/*if (st.size() == 0){
			if (op.front() == '-') st.push_back(-t);
			else st.push_back(t);
			op.erase(op.begin());
			break;
		}*/
		if (op.front() == '+') st[0] = t + st[0];
		if (op.front() == '-') st[0] = t - st[0];
		op.erase(op.begin());
	}
	
	return st[0];
}

int main()
{
	int n;
	char str[1024];
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%s", str);
		str[strlen(str) - 1] = '\0';
		printf("%d\n", calc(str, str + strlen(str)));
	}
	
	return 0;
}

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;
			if(xr<s.size()-1) 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;
			if(xr<s.size()-1) 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){
		if(xr>=s.size()-1) return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1));
		// if(xr>=s.size()-1) return foo1(s.substr(0,xl)+foo2(s.substr(xl+1,xr-xl-1)));
		return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1)+s.substr(xr+1));
		// return foo1(s.substr(0,xl)+foo2(s.substr(xl+1,xr-xl-1))+s.substr(xr+1));
	}
	return 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;
		// cout<<s.substr(0,0)<<endl;
		s=s.substr(0,s.size()-1);
		s=solve(s);
		cout<<s<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cctype>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef string::const_iterator State;

int ctoi(const char &c)
{
	return c - '0';
}

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

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

	while (true)
	{
		if (*itr == '+')
		{
			itr++;
			ret = ret + term(itr);
		}
		else if (*itr == '-')
		{
			itr++;
			ret = ret - term(itr);
		}
		else
		{
			break;
		}
	}

	return ret;
}

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

	while (true)
	{
		if (*itr == '*')
		{
			itr++;
			ret = ret*factor(itr);
		}
		else if (*itr == '/')
		{
			itr++;
			ret = ret / factor(itr);
		}
		else
		{
			break;
		}
	}

	return ret;
}

int factor(State &itr)
{
	int ret;

	if (*itr == '(')
	{
		itr++;
		ret = expression(itr);
		itr++;
	}
	else
	{
		ret = number(itr);
	}

	return ret;
}

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

	while (isdigit(*itr))
	{
		ret *= 10;
		ret += ctoi(*itr);
		itr++;
	}

	return ret;
}

int main()
{
	int n;
	cin >> n;
	cin.ignore();
	REP(i, n)
	{
		string str;
		getline(cin, str);
		State begin = str.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}
	return 0;
}

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

typedef string::const_iterator State;
int expression(State &begin);

int number(State &begin) {
	int ret = 0;
	for (; isdigit(*begin);) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}
int factor(State &begin) {
	int ret;
	if (*begin == '(') {
		begin++;
		ret = expression(begin);
		begin++;
	}
	else {
		return number(begin);
	}
	return ret;
}
int term(State &begin) {
	int ret = factor(begin);
	for (;;) {
		if (*begin == '*') {
			ret *= term(++begin);
		}
		else if (*begin == '/') {
			ret /= term(++begin);
		}
		else break;
	}
	return ret;
}


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

int main() {
	int N;
	cin >> N;
	cin.ignore();
	for (int i = 0; i < N; i++) {
		string str;
		getline(cin, str);
		cout << expression(str.begin()) << endl;
	}
	return 0;
}