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();
int p=0;
string str;
int main(){
  int n,re;
  cin >> n;
  while(n){
    p=0;
    cin >> str;
    re=exp();
    cout << re << endl;
    n--;
  }
  return 0;
}
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=number();
  if(str[p]=='('){
    p++;
    val=exp();
  }else if(str[p]==')'){
    p++;
  }
  return val;
}
int number(){
  int val=digit();
  return val;
}
int digit(){
  if(str[p]=='0'){
    p++;
    return 0;
  }
  else if(str[p]=='1'){
    p++;
    return 1;
  }
  else if(str[p]=='2'){
    p++;
    return 2;
  }
  else if(str[p]=='3'){
    p++;
    return 3;
  }
  else if(str[p]=='4'){
    p++;
    return 4;
  }
  else if(str[p]=='5'){
    p++;
    return 5;
  }
  else if(str[p]=='6'){
    p++;
    return 6;
  }
  else if(str[p]=='7'){
    p++;
    return 7;
  }
  else if(str[p]=='8'){
    p++;
    return 8;
  }
  else if(str[p]=='9'){
    p++;
    return 9;
  }
}

C++: #include<iostream>
#include <string>
#include <cctype>

using namespace std;

typedef string::const_iterator State;
class ParseError {};

int expression(State& base);
int number(State& base){
    int ret=0;
    while(isdigit(*base)){
        ret=ret*10+(*base-'0');
        base++;
    }
    return ret;
}
int factor(State& base){
    int ret;
    if(*base=='('){
        base++;
        ret=expression(base);
        base++;
        return ret;
    }
    else
        return number(base);
}
int term(State& base){
    int ret=factor(base);
    while(1){
        if(*base=='*'){
            base++;
            ret*=factor(base);
        }
        else if(*base=='/'){
            base++;
            ret/=factor(base);
        }
        else break;
    }
    return ret;
}
int expression(State& base){
    int ret=term(base);
    while(1){
        if(*base=='+'){
            base++;
            ret+=term(base);
        }
        else if(*base=='-'){
            base++;
            ret-=term(base);
        }
        else break;
    }
    return ret;
}
int main(){
    int n;
    cin>>n;
    while(n--){
        string str;
        cin>>str;
        State base = str.begin();
        cout<<expression(base)<<endl;
    }
}

C++: #include<iostream>
#include<sstream>

using namespace std;

string str;

bool isNum(string s){
  for(int i = 1; i < s.length(); i++)
    if(s[i] < '0' || s[i] > '9') return false;

  return true;
}

int solve(string s){

  // cout << s << endl;
  if(isNum(s)){
    if(s[0] != '-'){
      stringstream ss(s);
      int out;
      ss >> out;
      return out;

    }else{
      string s1 = "";

      for(int i = 1; i < s.length(); i++)
	s1+=s[i];
      stringstream ss(s1);
      int out;
      ss >> out;
      return -1*out;
    }
  }

  int pos = -1;


  for(int i = 0; i < s.length(); i++)
    if((i&&(s[i] == '+' || s[i] == '-')) ||  s[i] == '('){
      pos = i;
      break;
    }

  if(pos == -1){
    int now = 0;
    string a,b;
    a = b = "";

    for(int i = 0; i < s.length(); i++){
      if(s[i] == '*' || s[i] == '/'){
	now = i;
	break;
      }
      a += s[i];

    }

    for(int i = now+1; i < s.length(); i++)
      b+=s[i];

    if(s[now] == '+') return solve(a)+solve(b);
    if(s[now] == '-') return solve(a)-solve(b);
    if(s[now] == '*') return solve(a)*solve(b);
    if(s[now] == '/') return solve(a)/solve(b);

  }else{

    string a,b;
    a = b = "";

    for(int i = 0; i < pos; i++)
      a += s[i];
    for(int i = pos+1; i < s.length(); i++)
      b += s[i];

    if(s[pos] == '+') return solve(a)+solve(b);
    else if(s[pos] == '-') return solve(a)-solve(b);
    else if(s[pos] == '('){

      if(pos == 0){

	int par = 1;
	a = b = "";
	int now;

	for(int i = 1; i < s.length(); i++){
	  if(s[i] == '(') par++;
	  if(s[i] == ')') par--;
	  a+=s[i];
	  if(par == 0){
	    now = i+1;
	    break;
	  }
	}

	if(now == s.length()){
	  for(int i = 1; i < s.length()-1; i++)
	    b += s[i];

	  return solve(b);
	}

	for(int i = now+1; i < s.length(); i++)
	  b+=s[i];

	if(s[now] == '+') return solve(a)+solve(b);
	if(s[now] == '-') return solve(a)-solve(b);
	if(s[now] == '*') return solve(a)*solve(b);
	if(s[now] == '/') return solve(a)/solve(b);
	


      }else{
	a = b = "";

	for(int i = 0; i < pos-1; i++)
	  a+=s[i];

	for(int i = pos; i < s.length(); i++)
	  b+=s[i];

	if(s[pos-1] == '+') return solve(a)+solve(b);
	if(s[pos-1] == '-') return solve(a)-solve(b);
	if(s[pos-1] == '*') return solve(a)*solve(b);
	if(s[pos-1] == '/') return solve(a)/solve(b);
       
      }
    }
  }

}

string make(string s){
  string out = "";

  for(int i = 0; i < s.length()-1; i++)
    out += s[i];

  return out;
}

int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> str;
    str = make(str);
    cout << solve(str) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>

using namespace std;

int pos;
string str;

int str_to_int(string str) {
	if (str == "") return 0;

	int ret = 0;

	stringstream ss;
	ss << str;
	ss >> ret;

	return ret;
}

int keisan();
int kou();
int number();

int keisan() {
	int left = kou();

	while (str[pos] != '=' && str[pos] != ')') {
		char c = str[pos++];
		int right = kou();

		if (c == '+') left += right;
		else left -= right;
	}
	++pos;

	return left;
}
int kou() {
	int left = number();

	while (str[pos] == '*' || str[pos] == '/') {
		char c = str[pos++];
		int right = number();

		if (c == '*') left *= right;
		else left /= right;
	}

	return left;
}
int number() {
	string ret = "";

	if (str[pos] == '(') {
		++pos;
		return keisan();
	}
	while (str[pos] >= '0' && str[pos] <= '9')
		ret += str[pos++];

	return str_to_int(ret);
}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> str;

		pos = 0;

		cout << keisan() << endl;
	}
}