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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;


int main(){
    int n;
    string s;
    while(cin>>n){
        for(int i=0; i<n; i++){
            cin>>s;
            int j=0;
            
            queue<string> qu;
            stack<string> st;
            
            
            while(j<s.length()){
                //cout<<s[j]<<endl;
                //数値の処理
                if(s[j]>='0'&&s[j]<='9'){
                    string s_temp;
                    
                    while(s[j]>='0'&&s[j]<='9'){
                        s_temp+=s[j];
                        j++;
                    }
                    
                    qu.push(s_temp);
                    
                }
                
                //括弧の処理
                else if(s[j]==')'){
                    while(1){
                        string s_temp;
                        s_temp = st.top();
                        st.pop();
                        if(s_temp=="("){
                            break;
                        }else{
                            qu.push(s_temp);
                        }
                    }
                    j++;
                }
                
                else if(s[j]=='('){
                    string s_temp;
                    s_temp+=s[j];
                    st.push(s_temp);
                    j++;
                }
                
                //演算子の処理
                else if(s[j]=='-'||s[j]=='+'||s[j]=='*'||s[j]=='/'){
                    string s_temp;
                    s_temp+=s[j];
                    if(st.empty()){
                        st.push(s_temp);
                        j++;
                    }else{
                        if(!(s_temp=="*"||s_temp=="/")&&(st.top()=="-"||(st.top()=="+"))){
                            s_temp = st.top();
                            st.pop();
                            qu.push(s_temp);
                        }else{
                            st.push(s_temp);
                            j++;
                        }
                    }
                }
                //=の処理
                else if(s[j]=='='){
                    j++;
                }
                
                
            }
            while(!st.empty()){
                qu.push((st.top()));
                st.pop();
            }
            
            stack<int> num;
            while(!qu.empty()){
                
                //cout<<qu.front()<<endl;
                
                if(qu.front()=="*"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=a*b;
                    num.push(a);
                }else if(qu.front()=="/"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=b/a;
                    num.push(a);
                    
                }else if(qu.front()=="-"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=b-a;
                    num.push(a);
                }else if(qu.front()=="+"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=a+b;
                    num.push(a);
                }else{
                    stringstream stream;
                    stream<<qu.front();
                    int temp;
                    stream>>temp;
                    num.push(temp);
                }
                qu.pop();
            }
            cout<<num.top()<<endl;
        }
        
    }
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int n,tmp,op1,work;
	char line[101],calc;
	stack<int> NUM,work_num;
	stack<char> OP,work_op;

	bool numFLG,negFLG;

	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%s",line);

		tmp = 0;
		numFLG = false;
		negFLG = false;

		for(int k = 0; line[k] != '\0'; k++){
			if(line[k] >= '0' && line[k] <= '9'){
				numFLG = true;
				tmp = 10*tmp + (line[k] - '0');
			}else{

				if(numFLG == true){
					if(negFLG){
						tmp = -1*tmp;
						negFLG = false;
					}

					if(OP.empty() == false && (OP.top() == '*' || OP.top() == '/')){
						calc = OP.top();
						OP.pop();
						op1 = NUM.top();
						NUM.pop();

						if(calc == '*'){
							NUM.push(tmp*op1);
						}else{
							NUM.push(op1/tmp);
						}
					}else{
						NUM.push(tmp);
					}

					numFLG = false;
					tmp = 0;
				}


				if(line[k] == '+' ||line[k] == '*' || line[k] == '/' || line[k] == '('){
					OP.push(line[k]);
				}else if(line[k] == '-'){
					if(line[k-1] >= '0' && line[k-1] <= '9'){
						OP.push('-');
					}else if(line[k-1] == ')'){
						OP.push('-');
					}else{
						negFLG = true;
					}
				}else if(line[k] == ')'){

					work = NUM.top();
					NUM.pop();
					work_num.push(work);

					while(true){
						calc = OP.top();
						OP.pop();
						if(calc == '(')break;

						work_op.push(calc);

						work = NUM.top();
						NUM.pop();
						work_num.push(work);
					}

					work = work_num.top();
					work_num.pop();

					while(!work_num.empty()){
						calc = work_op.top();
						work_op.pop();

						if(calc == '+'){
							work += work_num.top();
						}else if(calc == '-'){
							work -= work_num.top();
						}else if(calc == '*'){
							work *= work_num.top();
						}else{
							work /= work_num.top();
						}
						work_num.pop();
					}

					NUM.push(work);

				}else{

					work = NUM.top();
					NUM.pop();
					work_num.push(work);

					while(!NUM.empty()){
						calc = OP.top();
						OP.pop();

						work_op.push(calc);

						work = NUM.top();
						NUM.pop();
						work_num.push(work);
					}

					work = work_num.top();
					work_num.pop();

					while(!work_num.empty()){
						calc = work_op.top();
						work_op.pop();

						if(calc == '+'){
							work += work_num.top();
						}else if(calc == '-'){
							work -= work_num.top();
						}else if(calc == '*'){
							work *= work_num.top();
						}else{
							work /= work_num.top();
						}
						work_num.pop();
					}

					printf("%d\n",work);
				}
			}
		}

	}


	return 0;
}