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 <bits/stdc++.h>
using namespace std;

string get_term(string, int&);
int get_num(string);
int get_exp(string);

int get_num(string str) {
    int num = 0;

    if (str.size() == 0) return 0;

    int i = 0;
    if (str[i] == '(') {
        i++;
        string exp;
        for (int count = 1; count; i++) {
            if (str[i] == '(') count++;
            if (str[i] == ')') count--;
            if (count) exp += str[i];
        }

        num = get_exp(exp + "=");
    } else {
        for (; '0' <= str[i] && str[i] < '9'; i++) {
            num = num * 10 + (str[i] - '0');
        }
    }

    for (; i < str.size(); i++) {
        if (str[i] == '*') {
            i++;
            return num * get_num(string(str.begin() + i, str.end()));
        } else {
            i++;
            return num / get_num(string(str.begin() + i, str.end()));
        }
    }

    return num;
}


void solve(string str) {
    cout << get_exp(str) << endl;
}

int main() {
    int N;
    cin >> N;

    while (N--) {
        string str;
        cin >> str;
        solve(str);
    }

    return 0;
}

string get_term(string str, int& i) {
    string init_str;
    for (int count = 0; i < str.size(); i++) {
        if (str[i] == '(') count++;
        if (count > 0 || ('0' <= str[i] && str[i] <= '9') || str[i] == '/' || str[i] == '*') {
            init_str += str[i];
        }
        if (str[i] == ')') count--;

        if (count == 0 && (str[i] == '+'|| str[i] == '-' || str[i] == '=')) {
            break;
        }
    }

    return init_str;
}

int get_exp(string str) {
    int num  = 0;
    int i = 0;

    string init_str = get_term(str, i);
    num = get_num(init_str);

    while (str[i] != '=') {
        if (str[i] == '-') {
            i++;
            string term = get_term(str, i);
            num -= get_num(term);
        } else if (str[i] == '+') {
            i++;
            string term = get_term(str, i);
            num += get_num(term);
        }
    }

    return num;
}

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){
    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();
  cout <<  val << endl;
  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(){
  cout << 'p' << p << endl;
  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 <stdio.h>

char stk[50], psh[50];
double v[50];
int pri[256], sp, pp;

int calc(char *p) {
  int i;
  char *exp = p;
  for (i = 0; i < 256; i++)
    pri[i] = 3;
  pri['+'] = pri['-'] = 1;
  pri['*'] = pri['/'] = 2;
  pri['('] = 4;
  pri[')'] = 0;
  stk[0] = 0;
  pri[0] = -1;
  sp = pp = 0;
  while (*p != '\0') {
    while (pri[*p] <= pri[stk[sp]] && stk[sp] != '(')
      psh[++pp] = stk[sp--];
    if (*p != ')')
      stk[++sp] = *p;
    else
      sp--;
    p++;
  }
  for (i = sp; i > 0; i--)
    psh[++pp] = stk[i];
  sp = 0;
  for (i = 1; i <= pp; i++) {
    if ('0' <= psh[i] && psh[i] <= '9')
      v[++sp] = psh[i] - '0';
    else {
      switch (psh[i]) {
      case '+':
        v[sp - 1] = v[sp - 1] + v[sp];
        break;
      case '-':
        v[sp - 1] = v[sp - 1] - v[sp];
        break;
      case '*':
        v[sp - 1] = v[sp - 1] * v[sp];
        break;
      case '/':
        v[sp - 1] = v[sp - 1] / v[sp];
        break;
      }
      sp--;
    }
  }
  printf("%d\n",(int)v[1]);
}
int main() {
  int i, j, n;
  char p[50][100];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%s", p[i]);
  for (i = 0; i < n; i++)
    for (j = 0; j < 100; j++)
      if (p[i][j] == '=')
        p[i][j] = '\0';
  for (i = 0; i < n; i++)
    calc(p[i]);
}

C++: #include <cmath>
#include <cassert>
#include <iostream>

using namespace std;

string S;
size_t cur = 0;

int digit() {
	int n;
	assert(isdigit(S[cur]));
	n = S[cur] -'0';
	++cur;
	return n;
}

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

int expression();
int factor() {
	int n;
	if (S[cur] != '(') n = number();
	else {
		++cur;
		n = expression();
		assert(S[cur] == ')');
	}
	return n;
}

int term() {
	int t = factor();
	while (cur < S.size() && (S[cur] == '*' || S[cur] == '/')) {
		char op = S[cur++];
		int b = factor();
		if(op == '*') t *= b; else t /= b;
	}
	return t;
}


/*int expression() {
	int sum = number();
	while (S[cur] == '+' || S[cur] == '-') {
		char op = S[cur++];
		int b = number();
		if(op == +) sum += b;	else return sum -= b;
	}
	return sum;
}*/

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


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