Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)

	for {
		var s string
		s = nextString()
		if s == "." {
			break
		}
		var st []byte
		is_valid := true

		for _, value := range s {
			if value == '(' {
				st = append(st, byte(value))
			}
			if value == '[' {
				st = append(st, byte(value))
			}
			if value == ')' {
				if len(st) == 0 || st[len(st)-1] != '(' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
			if value == ']' {
				if len(st) == 0 || st[len(st)-1] != '[' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
		}
		if len(st) != 0 {
			is_valid = false
		}
		if is_valid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    while (true)
    {
        getline(cin, s);
        //cout << s << endl;
        if (s == ".")
            break;
        int len = s.length();
        std::vector<char> v;
        for (int i = 0; i < len; i++)
        {
            if (s[i] == '(' || s[i] == ')' || s[i] == '[' || s[i] == ']')
            {
                v.push_back(s[i]);
            }
        }
        bool update = true;
        while (update)
        {
            update = false;
            int le = v.size();
            for (int i = 0; i < le - 1; i++)
            {
                if ((v[i] == '(' && v[i + 1] == ')') || (v[i] == '[' && v[i + 1] == ']'))
                {
                    v.erase(v.begin() + i, v.begin() + i + 2);
                    update = true;
                    i = le;
                }
            }
            //for(int i=0;i<v.size();i++) cout << v[i];
            //cout << endl;
        }
        if (v.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}

C++: #include<stdio.h>
char s[110],a[110],b,i,t;
main(){
  while(fgets(s,110,stdin)){
    if(s[1]=='\n'&&s[0]==46)break;
    for(t=1,b=0,i=0;s[i]&&t;++i){
      if(s[i]==40||s[i]==91) a[b++]=s[i];
      else if(s[i]==41||s[i]==93) {
        if(!b){t=0;break;}
        if((s[i]==41&&a[b-1]==40)||(s[i]==93&&a[b-1]==91)) --b;
        else t=0;
      }
    }
    puts(((t&&!b)?1:0)?"yes":"no");
  }
}

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

void test(){
    char c;
    while(scanf("%c",&c), c!='~'){
        cout << c << ", ";
    }
    cout << '\n';
}

bool q1(){
    int n,maxValue;
    cin >> n >> maxValue;
    if(n==0 && maxValue==0)return false;
    int value[n];
    int tempValue=0;
    int tempMax=0;
    for(int i=0;i<n;i++){
        cin >> value[i];
    }
    for(int top=0;top<n-1;top++){
    for(int i=1;i<n-top;i++){
        tempValue = value[top] + value[top+i];
        if(tempMax < tempValue && tempValue <= maxValue)tempMax=tempValue;
    }
    }
    if(tempMax==0){cout << "NONE" << "\n";return true;}
    cout << tempMax << "\n";return true;
}

bool q2(){
    char c;
    bool check = true;
    stack<char> st;
    st.push('0');
    if(scanf("%c",&c) && c == '.')return false;
    while(c != '.'){
        switch(c){
            case '(':
                st.push('(');break;
            case '[':
                st.push('[');break;
            case ')':
                if(st.top()!='('){check=false;break;}
                st.pop();break;
            case ']':
                if(st.top()!='['){check=false;break;}
                st.pop();break;
            default:
                break;
        }
        scanf("%c",&c);
    }
    cout << (check ? "yes" : "no") << '\n';
    scanf("%c",&c);
    return true;
}

int main()
{
    while(q2());
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
int t[17][17];
int dp[64 * 1024];
int main() {
	string buf;
	while (getline(cin, buf), buf != ".") {
		vector<char> s;
		bool f = true;
		for (auto a : buf) {
			switch (a) {
			case '(':
			case '[':
				s.push_back(a);
				break;
			case ')':
				if (s.empty() || s.back() != '(') {
					f = false;
					break;
				}
				s.pop_back();
				break;
			case ']':
				if (s.empty() || s.back() != '[') {
					f = false;
					break;
				}
				s.pop_back();
				break;
			}
		}
		if (!s.empty())f = false;
		cout << (f ? "yes" : "no") << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include<vector>

using namespace std;

int main(){
	string a;
	bool IsOk = true;
	bool b = false;
	bool IsFinish = false;
	vector<int> v;
	while (cin >> a){
		if (IsFinish==true&&a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}else{
			b = false;
			IsFinish = false;
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (v.empty() == false){
					if (v.back() != 1){
						IsOk = false;
					}
					v.pop_back();
				}
				else{
					IsOk = false;
				}
				
			}
			else if (a[i] == 91){//[
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (v.empty() == false && v.back() != 0){
					IsOk = false;
				}
				else{
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (v.empty()==false){
					IsOk = false;
				}
				if (IsOk == true){cout << "yes"<<endl;
				}else{            cout << "no" <<endl;}
				IsOk = true; 
				v.clear();
				IsFinish = true;
			}
		}
	}
	return 0;
}

C++: //
//  main.cpp
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <stack>
using namespace std;
int main(int argc, const char * argv[]) {
    
    string yn = "yes";
    while(1){
        string str;
        stack<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push(str[i]);
            }
            
            if (str[i] == ')' || str[i] == ']') {
                char s = st.top();
                st.pop();
                if (!(s == str[i])) {
                    yn = "no";
                    break;
                }
            }
        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}