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;
#define int long long
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);

bool f;

int expression(string s,int& p){
  int res=term(s,p);
  while(p<(int)s.size()){
    if(s[p]=='+'){
      p++;
      res+=term(s,p);
      continue;
    }
    if(s[p]=='-'){
      p++;
      res-=term(s,p);
      continue;
    }
    break;
  }
  return res;
}

int term(string s,int& p){
  int res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='*'){
      p++;
      res*=factor(s,p);
      continue;
    }
    if(s[p]=='/'){
      p++;
      int tmp=factor(s,p);
      if(tmp==0){
	f=1;
	break;
      }
      res/=tmp;
      continue;
    }
    break;
  }
  return res;
}

int factor(string s,int& p){
  int res;
  if(s[p]=='('){
    p++;
    res=expression(s,p);
    p++;
  }else{
    res=number(s,p);
  }
  return res;
}

int number(string s,int& p){
  int res=0;
  while(p<(int)s.size()&&isdigit(s[p]))
    res=res*10+s[p++]-'0';
  return res;
}

signed main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    int p=0;
    cin>>s;
    s.pop_back();
    cout<<expression(s,p)<<endl;
  }
  return 0;
}

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

int p=0;
int formula(string& s);

int num(string& s){
    int res=0;
    int op=1;
    if(s[p]=='-'){
        op=-1;
        p++;
    }
    else if(s[p]=='+'){
        op=1;
        p++;
    }
    while(isdigit(s[p])){
        res*=10;
        res+=s[p]-'0';
        p++;
    }
    return op*res;
}

int term(string & s){
    if(s[p]=='('){
        p++;
        int res=formula(s);
        p++;
        return res;
    }
    return num(s);
}

int section(string& s){
    int res=term(s);
    while(p!=s.size() && s[p]!=')' && s[p]!='+' && s[p]!='-'){
        char op=s[p];
        p++;
        int next=term(s);
        if(op=='*') res*=next;
        else res/=next;
    }
    return res;
}

int formula(string& s){
    int res=section(s);
    while(p!=s.size() && s[p]!=')'){
        char op=s[p];
        p++;
        int next=section(s);
        if(op=='+') res+=next;
        else res-=next;
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        s.pop_back();
        p=0;
        cout<<formula(s)<<endl;
    }
    return 0;
}

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


string S;
size_t cur = 0;
int parse();
int expression();


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

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

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

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

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

  //   }

  // }


  // int a = number();
  // char op = S[cur];
  // cur += 1;
  // int b = number();
  // assert(op == '+');
  // return a + b;
}



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;
  }
}
// int parse(){return expression();}
// int main(){
//   int a = parse();
//   // assert(a==15);
//   cout << a << endl;
//   assert(cur == S.size());
// }

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<iostream>
#include<queue>
#include<cctype> // isdigit
#include<cassert> // assert
#include<cstdlib> // atoi

using namespace std;

queue<string>exp;

int calculate();
int add();
int multiply();
int term();

int calculate()
{
  return add();
}

int add()
{
  int num=multiply();
  if(exp.empty())return num;
  string s=exp.front();
  if(s[0]=='+'||s[0]=='-'){
    exp.pop();
    int num2=calculate();
    if(s[0]=='+')return num+num2;
    if(s[0]=='-')return num-num2;
  }
  return num;
}

int multiply()
{
  int num=term();
  if(exp.empty())return num;
  string s=exp.front();
  if(s[0]=='*'||s[0]=='/'){
    exp.pop();
    int num2=calculate();
    if(s[0]=='*')return num*num2;
    if(s[0]=='/')return num/num2;
  }
  return num;
}

int term()
{
  string s=exp.front();
  // l
  if(isdigit(s[0])){
    exp.pop();
    return atoi(s.c_str());
  }
  // PZqÌ}CiX
  if(s[0]=='-'){
    exp.pop();
    return -calculate();
  }
  // Ê
  if(s[0]=='('){
    exp.pop();
    int num=calculate();
    assert(exp.front()==")");
    exp.pop();
    return num;
  }
}

int main()
{
  int n;
  string s;
  cin>>n;
  while(n-->0){
    cin>>s;
    while(exp.size())exp.pop();
    for(int i=0;i<s.size();i++){
      if(s[i]=='=')break;
      if(isdigit(s[i])){
	int j;
	for(j=i+1;j<s.size();j++)if(!isdigit(s[j]))break;
	exp.push(s.substr(i,j-i));
	i=j-1;
      }else{
	exp.push(s.substr(i,1));
      }
    }
    /*
    while(exp.size()){
      cout<<exp.front()<<endl;
      exp.pop();
    }
    */
    cout<<calculate()<<endl;
  }
}