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

using namespace std;

#if 0
所用時間:

感想:

#endif

string S;
size_t cur;

int expression();
int factor();

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

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 term(){
    int a = factor();
    while(cur < S.size() && (peek()=='*' || peek()=='/')){
        char op = readchar();
        int b = factor();
        if(op=='*') a*= b;
        else a /= b;
        // cout << "calc: " << a << " " << op << " " << b << endl;
    }
    return a;
}

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

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


int parse(){
    return expression();
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> S;
        cur = 0;
        S.resize(S.size()-1); // 最後の=を無視
        int a = parse();
        cout << a << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
using namespace std;
typedef string::const_iterator State;
class ParseError {};

int term(State &begin);
int expression(State &begin);
int factor(State &begin);
int number(State &begin);
void consume(State &begin, char expected);

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

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

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

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

// begin???expected?????????????????????begin?????????????????????
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
            << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

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

C++: #include <iostream>
#include <cmath>
#include <stack>
#include <algorithm>
#include <sstream>
using namespace std;
int hoge(string a)
{
	if(a=="(")return -1;
	if(a=="*"||a=="/")return 1;
	return 0;
}

long long calc(long long a,long long b,string str)
{
	if(str=="+")return a+b;
	if(str=="-")return a-b;
	if(str=="/")return a/b;
	if(str=="*")return a*b;
	
}

int main()
{
	int n;cin>>n;
	while(n--)
	{
		string str;cin>>str;
		stringstream ss;
		for(int i=0;i<str.size()-1;i++)
		{
			if(str[i]=='+'||str[i]=='-'||str[i]=='/'||str[i]=='*'||str[i]=='('||str[i]==')')ss<<" "<<str[i]<<" ";
			else ss<<str[i];
		}
		
		vector<string> v;
		stack<string> st;
		while(getline(ss,str,' '))
		{
			if(str=="")continue;
			if(str=="+"||str=="-"||str=="/"||str=="*")
			{
				while(!st.empty()&&hoge(st.top())>hoge(str))
				{
					v.push_back(st.top());
					st.pop();
				}
				st.push(str);
			}
			else if(str==")")
			{
				while(st.top()!="(")
				{
					v.push_back(st.top());
					st.pop();
				}
				st.pop();
			}
			else if(str=="(")st.push(str);
			else v.push_back(str);
		}
		while(!st.empty())
		{
			
			v.push_back(st.top());
			st.pop();
		}
		stack<long long> k;
		for(int i=0;i<v.size();i++)
		{
			
			if(v[i]=="+"||v[i]=="-"||v[i]=="/"||v[i]=="*")
			{
				long long A,B;
				B=k.top();k.pop();
				A=k.top();k.pop();
				k.push(calc(A,B,v[i]));
			}
			else
			{
				k.push(atol(v[i].c_str()));
			}
		}
				cout<<k.top()<<endl;
	}
	
}

C++: #include<iostream>
#define INF (1<<26)
using namespace std;
int n;



int compute(int a,int b,string str){

  int i=a,sum=0,tmp=INF,tmp2=INF,cnt=0;
  while(1){ //cout<<a<<' '<<b<<endl;
    
    sum=0;
    if(str[i]=='('){
      sum=compute(i+1,0,str);
      //cout<<sum<<endl;
      cnt=0;
      for(i=i;i<(int)str.size();i++){
	if(str[i]==')')cnt--;
	if(str[i]=='(')cnt++;
	if(cnt==0)break;
      }
      i++;
      
    }else{
      while(1){
	if('0'<=str[i]&&str[i]<='9'){
	  sum*=10;
	  sum+=(str[i]-'0');
	  i++;
	}else{
	  break;
	}
      }
    }

    if(b==1){
      sum*=-1;
      b=0;
    }
    if(tmp!=INF){
      sum*=tmp;
      tmp=INF;
    }
    if(tmp2!=INF){
      sum=tmp2/sum;
      tmp2=INF;
    }
    //if(a==8)cout<<sum<<endl;    
    if(str[i]=='\0'||str[i]==')'||str[i]=='='||i==(int)str.size())return sum;
    if(str[i]=='+')return sum + compute(i+1,0,str);
    if(str[i]=='-')return sum + compute(i+1,1,str);
    if(str[i]=='*'){
      i++;
      tmp=sum;
    }else if(str[i]=='/'){
      i++;
      tmp2=sum;
    }
  }
      
}


int main(){
  string str;
  cin>>n;
  while(n--){
    cin>>str;

    //cout<<str<<endl;
    cout<<compute(0,0,str)<<endl;
  }
  return 0;
}