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 <cassert>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>

namespace {
  
int operate(char op, int arg1, int arg2)
{
  switch (op) {
  case ')':
  case '=': return arg1;
  case '+': return arg1 + arg2;
  case '-': return arg1 - arg2;
  case '*': return arg1 * arg2;
  case '/': assert(arg2 != 0); return arg1 / arg2;
  }
  assert(0);
}

int evaluate(std::string& str, size_t first, size_t last)
{
  size_t current = 0;
  std::vector<int> arg;
  std::vector<char> op;

  arg.push_back(0);
  
  for (size_t pos = first; pos <= last; ) {
  	
    // 数字
    if (isdigit(str[pos])) {
      arg[current] = (arg[current] * 10) + (str[pos] - '0');
       ++pos;
      continue;
    }

    // 括弧
    if (str[pos] == '(') {
      size_t paren_end = pos + 1;
      int nest = 0;

      // 括弧に対応する閉じ括弧の場所を検索
      for (; paren_end <= last; ++paren_end) {
        if (str[paren_end] == ')') {
          if (!nest) break;
          else --nest;
        }
        else if (str[paren_end] == '(') {
          ++nest;
        }
      }

      assert(paren_end != last + 1);
      arg[current] = evaluate(str, pos + 1, paren_end);
      pos = paren_end + 1;
      continue;
    }

    // 演算子
    op.push_back(char(str[pos]));
    if (current == 0) {
      ++current;
      arg.push_back(0);
      ++pos;
      continue;
    }

    if (op[current - 1] == '*' || op[current - 1] == '/') {
      arg[current - 1] = operate(op[current - 1], arg[current - 1], arg[current]);
      op[current - 1] = op[current];
      arg[current] = 0;
      op.pop_back();
    } 
    else {
      ++current;
      arg.push_back(0);
    }
    ++pos;
  }
  
  // + -
  
  for (size_t i = 1; i < current; ++i) {
  	arg[0] = operate(op[i - 1], arg[0], arg[i]);
  }
  
  return arg[0];
}

} // unnamed namespace

int main()
{
  int n;
  std::cin >> n;
  
  for (int i = 0; i < n; ++i) {
    std::string exp;
    std::cin >> exp;

    std::cout << evaluate(exp, 0, exp.size()) << std::endl;
  }

  return 0;
}

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

using namespace std;

string S;
size_t cur;
int x;

char readchar(){
	assert(cur < S.size());
	return S[cur++];
}

char peek(){
	assert(cur < S.size());
	return S[cur];
}

int digit(){
	assert(isdigit(peek()));
	int n = readchar() - '0';
	return n;
}

int number(){
	int n = digit();
	while (cur < S.size() && isdigit(peek())){
		n = n*10 + digit();
	}
	return n;
}

int expression();
int factor(){
	if (peek() != '(') return number();
	cur += 1;
	int n = expression();
	assert(peek()==')');
	cur+=1;
	return n;
}

int term(){
	int a = factor();
	while(cur < S.size() && (peek()=='*' || peek()=='/')){
		char op = readchar();
		int b = factor();
		if (op=='*'){
			a = a*b;
		}else{
			a = a/b;
		}
	}
	return a;
}

int expression(){
	int a = term();
	while(cur < S.size() && (peek()=='+' || peek()=='-')){
		char op = readchar();
		int b = term();
		if (op == '+'){
			a = a+b;
		}else{
			a = a-b;
		}
	}
	return a;
}

int main() {
	cin >> x;
	for (int i=1; i<=x; i++){
		cin >> S;
		cur = 0;
		S.resize(S.size()-1);
		cout << expression() << endl;
	}
}

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

using namespace std;

string s;
int id;

int exp();
int term();
int fact();

int exp()
{
	int r = term();
	while(true)
	{
		char c = s[id++];
		if(c == '+')r += term();
		else if(c == '-')r -= term();
		else break;
	}
	return r;
}

int term()
{
	int r = fact();
	while(true)
	{
		char c = s[id++];
		if(c=='*') r*=fact();
		else if(c=='/')r/=fact();
		else break;
	}
	id--;
	return r;
}

int fact()
{
	char c = s[id++];
	if(c=='(')return exp();
	if(c=='-')
	{
		return -fact();
	}
	if(c=='+')
	{
		return fact();
	}
	int x = c-'0';
	while(true)
	{
		c = s[id++];
		if('0' <= c && c <= '9')
		{
			x *= 10;
			x += c-'0';
		}
		else break;
	}
	id--;
	return x;
}

void solve()
{
	int N;
	scanf("%d\n", &N);
	while(N--)
	{
		getline(cin, s);
		id = 0;
		cout << exp() << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

typedef long long Int;
typedef string::const_iterator Iter;

Int eval(const string&);
Int expr(Iter&);
Int term(Iter&);
Int factor(Iter&);
Int number(Iter&);

Int eval(const string &s){
	Iter it = s.begin();
	return expr(it);
}

Int expr(Iter &it){
	Int res = term(it);
	while (true){
		if (*it == '+'){
			++it;
			res += term(it);
		}
		else if (*it == '-'){
			++it;
			res -= term(it);
		}
		else return res;
	}
}

Int term(Iter &it){
	Int res = factor(it);
	while (true){
		if (*it == '*'){
			++it;
			res *= term(it);
		}
		else if (*it == '/'){
			++it;
			res /= term(it);
		}
		else return res;
	}
}

Int factor(Iter &it){
	if (*it == '('){
		++it;
		Int res = expr(it);
		++it;
		return res;
	}
	else return number(it);
}

Int number(Iter &it){
	Int res = 0;
	while (isdigit(*it)){
		res = res * 10 + (*it - '0');
		++it;
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++){
		string s;
		getline(cin, s);
		cout << eval(s) << endl;
	}
}

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

class calc{
  string s;
  string::iterator it;

public:
  calc(const string&str){
    s = str;
    it = s.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 term(){
    int ret = fact();
    while(*it == '*' || *it == '/'){
      if(*it == '*'){
	++it;
	ret *= fact();
      }
      else if(*it == '/'){
	++it;
	ret /= fact();
      }
    }
    return ret;
  }
  
  int exp(){
    int ret = term();

    while(*it == '+' || *it == '-'){
      if(*it == '+'){
	++it;
	ret += term();
      }
      else if(*it == '-'){
	++it;
	ret -= term();
      }
    }
    return ret;
  }
};

int main(){
  string str;
  int n;

  cin >> n;
  while(n--){
    cin >> str;
    calc ans(str);
    cout << ans.exp() << endl;
  }

  return 0;
}

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


typedef string::const_iterator State;


int expression(State &begin);


int number(State &begin)
{
	int ret = 0;
	
	for(; isdigit(*begin); begin++) {
		ret = ret * 10 + *begin - '0';
	}

	return ret;
}

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

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

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

	return ret;
}

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

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

	return ret;
}


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

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