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 <iostream>
#include <stack>
#include <string>

using namespace std;

bool solve(string s) {
    stack<char> st;
    for (string::iterator i = s.begin(); i != s.end(); i++) {
        switch (*i) {
            case '(':
                st.push('(');
                break;
            case ')':
                if (!st.empty() && st.top() == '(') {
                    st.pop();
                } else {
                    return false;
                }
                break;
            case '[':
                st.push('[');
                break;
            case ']':
                if (!st.empty() && st.top() == '[') {
                    st.pop();
                } else {
                    return false;
                }
                break;
        }
    }
    if (st.empty()) return true;
    else return false;
}

int main() {
    string s;
    while (getline(cin, s)) {
        if (s == ".") break;
        if (solve(s)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

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

stack<char> st;

int main(){
	string s;
	while(getline(cin, s), s != "."){
		int len = s.size();
		bool flag = true;
		for(int i = 0; i < len; i++){
			if(s[i] == '(' ) st.push('(');
			else if(s[i] == '[' ) st.push('[');

			if(s[i] == ')' ){
				if(st.top() != '(' or st.empty()) flag = false;
				st.pop();
			}
			else if(s[i] == ']' ){
				if(st.top() != '[' or st.empty()) flag = false;
				st.pop();
			}
		}
		if(!st.empty() or !st.empty()) flag = false;

		if(flag) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int cnt1,cnt2;
int temp1[100],temp2[100];
string s;
int main(){
	while(1){
		getline(cin,s);
		if(s[0]=='.')break;
		cnt1=cnt2=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='('){
				cnt1++;
				temp1[cnt1]=cnt2;
			}else if(s[i]==')'){
				if(temp1[cnt1]!=cnt2)break;
				cnt1--;
			}else if(s[i]=='['){
				cnt2++;
				temp2[cnt2]=cnt1;
			}else if(s[i]==']'){
				if(temp2[cnt2]!=cnt1)break;
				cnt2--;
			}
			if(cnt1<0||cnt2<0)break;
		}
		if(cnt1==0&&cnt2==0){
			cout <<"yes" <<endl;
		}else{
			cout <<"no" <<endl;
		}
	}
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	string s;
	while(getline(cin, s), s != "."){
		vi v;
		bool ok = 1;
		rep(i, s.size()){
			if(s[i] == '(') v.pb(1);
			if(s[i] == ')'){
				if(!v.size() || v.back() != 1) ok = 0;
				else v.pop_back();
			}
			if(s[i] == '[') v.pb(2);
			if(s[i] == ']'){
				if(!v.size() || v.back() != 2) ok = 0;
				else v.pop_back();
			}
			if(!ok) break;
		}
		cout << (ok ? "yes" : "no") << endl;
	}
	return 0;
}

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

int main() {
	string S;
	while (getline(cin, S)) {
		if (S == ".") return 0;
		string T;
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == '(' || S[i] == '[' || S[i] == ')' || S[i] == ']') T = T + S[i];
		}
		stack<char> Q;
		bool check = true;
		for (int i = 0; i < T.size(); i++) {
			if (T[i] == '(' || T[i] == '[') Q.push(T[i]);
			if (T[i] == ')') {
				if (Q.empty()) check = false;
				else {
					if (Q.top() != '(') check = false;
					Q.pop();
				}
			}
			if (T[i] == ']') {
				if (Q.empty()) check = false;
				else {
					if (Q.top() != '[') check = false;
					Q.pop();
				}
			}
		}
		if (!Q.empty()) check = false;
		cout << (check ? "yes" : "no") << endl;
	}
}

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

char s[3] = "([";
char e[3] = ")]";

int main(int argc, const char * argv[]) {
    while(1){
        string line; getline(cin, line);
        if(line == ".") break;
        
        bool ok = true;
        stack<char> brackets;
        for(int i = 0; i < line.size(); i++){
            for(int j = 0; j < 2; j++){
                if (line[i] == s[j]) {
                    brackets.push(line[i]);
                } else if (line[i] == e[j]){
                    if(brackets.empty()){
                        ok = false;
                    } else {
                        ok = (brackets.top() == s[j]);
                        brackets.pop();
                    }
                }
            }
            if(!ok) break;
        }
        cout << (ok ? "Yes" : "No") << endl;
        
    }
}

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

int main(){
	stack<char> st;
	string str;
	bool f;
	while(getline(cin,str)){
		f = true;
		if(str == ".") break;
		for(int i = 0;i < str.size();++i){
			if(str[i] == '(' || str[i] == '['){
				st.push(str[i]);
			}
			if(!st.empty() && str[i] == ')' && st.top() == '('){
				st.pop();
			}
			if(!st.empty() && str[i] == ']' && st.top() == '['  ){
				st.pop();
			}
		}
		if(!st.empty()) f = false;
		if(f) cout << "yes" << endl;
		else cout << "no" << endl;
		while(!st.empty()){
			st.top();
			st.pop();
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  while(1){
    stack<int> s;
    bool ac = true;
    s.push('.');
    getline(cin,str);
    if(str == ".")break;
    for(int i=0;i<str.size();i++){
      if(str[i] == '[' || str[i] == ']' || str[i] == '(' || str[i] ==')'){
	if(str[i] == '[' || str[i] == '('){
	  s.push(str[i]);
	}
	if(str[i] == ']'){
	  if(s.top() == '['){
	    s.pop();
	  }else{
	    ac = false;
	  }
	}else if(str[i] == ')'){
	  if(s.top() == '('){
	    s.pop();
	  }else{
	    ac = false;
	  }
	}
      }
      if(!ac)break;
      
    }
    s.pop();
    if(!s.empty())ac = false;
    if(!ac)cout << "no" << endl;
    else cout << "yes" << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <string>
using namespace std;

main() {
string str;
while(getline(cin, str), str!="."){
    string tmp = "";
    for(int i = 0; i < str.size(); i++) {
        if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']')
            tmp += str[i];
    }
    bool f = 1;
    stack<char> stk;
    for(int i = 0; i < tmp.size(); i++) {
        if (tmp[i] == '(' || tmp[i] == '[')
            stk.push(tmp[i]);
        else if (!stk.empty()){
            char top = stk.top();
            stk.pop();
            if (tmp[i] == ')' && top == '(') {

            } else if (tmp[i] == ']' && top == '['){
            } else {
                f = 0;
            }
        } else {
        f = 0;
        }
    }
    if (!stk.empty()) f = 0;
    cout << (f ? "yes" : "no") << endl;
}
}