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 <stack>
#include <map>
#include <string>
#include <cctype>
using namespace std;

map<char,int> order;
string S; size_t cur=0;
stack<int> num,rnum;
stack<char> op,rop;

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

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

void calc(){
	int b=num.top();num.pop();
	int a=num.top();num.pop();
	char o=op.top();op.pop();
	int c;
	switch(o){
		case '+' :
			c=a+b;
			break;
		case '-' :
			c=a-b;
			break;
		case '*' :
			c=a*b;
			break;
		case '/' :
			c=a/b;
			break;
		default :
			break;
	}
	num.push(c);
	return ;
}

void calc2(){
	int a=rnum.top();rnum.pop();
	int b=rnum.top();rnum.pop();
	char o=rop.top();rop.pop();
	int c;
	switch(o){
		case '+' :
			c=a+b;
			break;
		case '-' :
			c=a-b;
			break;
		case '*' :
			c=a*b;
			break;
		case '/' :
			c=a/b;
			break;
		default :
			break;
	}
	rnum.push(c);
	return ;
}

int exp(){
	cur =0;
	int smax=S.size();
	while(cur < smax-1){
		//cout << cur << endl;
		if(isdigit(S[cur])){
			int a=number();
			num.push(a);
		}else if(!op.empty()&&op.top()!='('&&op.top()!=')'&& order[S[cur]] >= order[op.top()]){ //計算順序については改善の余地あり (　は最小に
			calc();
			op.push(S[cur++]);
		}else if(S[cur] == ')' ){
			rnum.push(num.top());num.pop();
 			while(!op.empty()&&op.top()!='('){
				rop.push(op.top());op.pop();
				rnum.push(num.top());num.pop();
			}
			while(!rop.empty())
				calc2();
			num.push(rnum.top());rnum.pop();
			//cout << num.top() << endl;
			op.pop();cur++;
		}else{//ひとまず終了　演算記号のチェックも入れる
			//	cout << "come" << endl;
			op.push(S[cur++]);
		}
	}
	if(!op.empty())
		calc();
	//cout << num.top() << endl;//
	//int tmp=num.top();num.pop();
	//cout << num.top() << endl;//
	//num.push(tmp);

	rnum.push(num.top());num.pop();
	while(!op.empty()&&op.top()!='('){
		rop.push(op.top());op.pop();
		rnum.push(num.top());num.pop();
	}
	while(!rop.empty())
		calc2();
	num.push(rnum.top());rnum.pop();
	//cout<< " check "  << op.empty() << endl;
	int ans=num.top();
	num.pop();
	return ans;
}

int main(void){
	order['+']=2;
	order['-']=2;
	order['*']=1;
	order['/']=1;
	//cout << order['('] << endl;
	int n;
	cin >> n;
	while(n--){
		cin >> S;
		cout << exp() << endl;
	}
	return 0;
}

C++: for t in xrange(input()):
	print eval(raw_input()[:-1])

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

long calc2(char *eq){
	long c=0, sign[100]={0};
	long num[100]={0};
	char *p = eq;
	while(*p){
		if('0'<=*p && *p<='9') num[c]=num[c]*10+*p-'0';
		else{
			if(*p=='+') sign[c]=1;
			else if(*p=='-') sign[c]=2;
			else if(*p=='*') sign[c]=3;
			else if(*p=='/') sign[c]=4;
			else if(*p=='=') break;
			else printf("err %c\n", *p);
			c++;
		}
		p++;
	}
	c++;
	for(int i=0;i<c-1;i++){
		if(sign[i]==3 || sign[i]==4){
			if(sign[i]==3)	num[i+1] = num[i] * num[i+1];
			if(sign[i]==4)	num[i+1] = num[i] / num[i+1];
			for(long j=i+1;j<c;j++){
				num[j-1] = num[j];
				sign[j-1] = sign[j];
			}
			i--;
			c--;
		}
	}
	for(int i=0;i<c-1;i++){
		if(sign[i]==1 || sign[i]==2){
			if(sign[i]==1)	num[i+1] = num[i] + num[i+1];
			if(sign[i]==2)	num[i+1] = num[i] - num[i+1];
			for(long j=i+1;j<c;j++){
				num[j-1] = num[j];
				sign[j-1] = sign[j];
			}
			i--;
			c--;
		}
	}
	return num[0];
}

long calc(char *eq){
	char *p, *p2, buf[120]={0}, cp[120]={0};
	long k,ret;
	strcpy(cp, eq);
	while((p=strchr(cp, '('))!=NULL){
		for(k=0,p2=p+1;;p2++)
			if(*p2=='(')k++;
			else if(*p2==')'){
				if(k)k--;
				else break;
			}
		memcpy(buf, p+1, p2-p-1);
		buf[p2-p-1]='=';
		buf[p2-p]=0;
		ret = calc(buf);
		*p=0;
		sprintf(buf, "%s%ld%s", cp, ret, p2+1);
		strcpy(cp,buf);
	}
	return (long)calc2(cp);
}

int main(){
	long i,j,n;
	char buf[120], p;
	for(cin >> n;n;n--){
		cin >> buf;
		cout << calc(buf) <<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <int> VI;
typedef vector <char> VC;

string toNums( string s ) {
    string R = "*/+";
    for ( int i = 0; i < 3; ++ i ) {
        replace( s.begin(), s.end(), R[i], ' ' );
    }
    return s;
}

string toOps( string s ) {
    string R = "0123456789-";
    for ( int i = 0; i < 11; ++ i ) {
        replace( s.begin(), s.end(), R[i], ' ' );
    }
    return s;
}

int eval( string expr ) {
    stack <int> S;
    for ( int i = 0; i < (int)expr.size(); ++ i ) {
        if ( expr[i] == '(' ) {
            S.push( i );
        } else if ( expr[i] == ')' ) {
            int left = S.top();
            int right = i;
            string L = expr.substr( 0, left );
            string M = expr.substr( left, right - left + 1 );
            string R = expr.substr( right + 1 );
            ostringstream os;
            os << eval( M.substr( 1, M.size()-2 ) );
            expr = L + os.str() + R;
            i = -1;
            S = stack <int>();
            continue;
        }
    }
    string nums = toNums( expr );
    string ops = toOps( expr );
    VI N;
    int num;
    istringstream is1( nums );
    while ( is1 >> num ) {
        N.push_back( num );
    }
    VC O;
    char op;
    istringstream is2( ops );
    while ( is2 >> op ) {
        O.push_back( op );
    }
    for ( int i = 0; i + 1 < (int)N.size(); ++ i ) {
        int a = N[i], b = N[i+1];
        char c = O[i];
        if ( c == '*' ) {
            N.erase( N.begin() + i );
            char cc = O[i+1];
            O.erase( O.begin() + i );
            N[i] = a * b;
            O[i] = cc;
            i --;
        } else if ( c == '/' ) {
            N.erase( N.begin() + i );
            char cc = O[i+1];
            O.erase( O.begin() + i );
            N[i] = a / b;
            O[i] = cc;
            i --;
        }
    }
    int answer = accumulate( N.begin(), N.end(), 0 );
    return answer;
}

bool isOp( char c ) {
    string O = "+-*/";
    for ( int i = 0; i < 4; ++ i ) {
        if ( c == O[i] ) return true;
    }
    return false;
}

string convert( string s ) {
    for ( int i = 0; i < (int)s.size(); ++ i ) {
        if ( s[i] != '-' ) continue;
        string L = s.substr( 0, i );
        string R = s.substr( i );
        s = L + ( (i>0 && isOp( s[i-1] )) || i == 0 ? " " : "+" ) + R;
        i ++;
    }
    return s;
}

int main() {
    int n;
    while ( cin >> n ) {
        if ( n == 0 ) break;
        for ( int i = 0; i < n; ++ i ) {
            string line;
            cin >> line;
            line = convert( line );
            cout << eval( line.substr( 0, line.size() - 1 ) ) << endl;
        }
    }
    return 0;
}