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

using namespace std;
int main(int argc,char **argv){
	vector<string> inputs;

	while(true){
		string line;
		getline(cin,line);
		if(line == "."){ break; }
		inputs.push_back( line );
	}

	for(auto it=inputs.begin();it!=inputs.end();++it){
		stack<char> st;
		bool isok=true;
		for(auto cit=it->begin();cit!=it->end();++cit){
			char c = *cit;
			if(c=='('||c=='['){ st.push(c); }
			else if(c==')'){
				if(st.size()==0){isok=false;break;}
				if(st.top()=='('){ st.pop(); }
				else{ isok=false; break; }
			}
			else if(c==']'){
				if(st.size()==0){isok=false;break;}
				if(st.top()=='['){ st.pop(); }
				else{ isok=false; break; }
			}
		}
		isok = isok && st.empty();
		cout << (isok?"yes":"no") << endl;
	}

}

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

using namespace std;

int main() {
	string a;
	const string b = "()[]";
	while (getline(cin, a)) {
		if (a.size() == 1 && a[0] == '.') {
			break;
		}
		int count[4] = {0};
		bool hantei = true;
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					count[j]++;
					break;
				}
			}
			if (count[0] < count[1]) {
				hantei = false;
				break;
			} else if (count[2] < count[3]) {
				hantei = false;
				break;
			}
		}

		if (hantei && (count[0] == count[1] && count[2] == count[3])) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	vector<string> s;
	
	while (1) {
		string ss;
		getline(cin, ss);
		if (ss == ".") break;

		int a[2] = {};
		bool flag = true;

		stack<int> st;
	
		for (int j = 0; j < ss.length(); j++) {

			if (ss[j] == '(') st.push(0);
			if (ss[j] == ')') {
				if (st.empty() || st.top() != 0 ) {
					flag = false;
					break;
				}
				else st.pop();
			}
			if (ss[j] == '[') st.push(1);
			if (ss[j] == ']') {
				if (st.empty() || st.top() != 1) {
					flag = false;
					break;
				}
				else st.pop();
			}
		}

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

	}

	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>


#define rep(i,n) for(i=0;i<n;i++)

using namespace std;




int main(){
	
	string s;
	
	int q[111];
	int qn;
	int i;
	bool f;
	
	fill(q,q+110,0);qn=0;
	f=true;
	
	
	while(true){
		//scanf("%s",s);
		
		getline(cin,s);
		
		if(s[0]=='.'&&s[1]==0)break;
		
		

		
		for(i=0;s[i]!=0;i++){
			if(f && s[i]=='('){
				q[qn++]=1;
			}
			if(f && s[i]=='['){
				q[qn++]=2;
			}
			if(f && s[i]==')'){
				if(qn==0){f=false;}
				if(q[--qn]!=1){f=false;}
			}
			if(f && s[i]==']'){
				if(qn==0){f=false;}
				if(q[--qn]!=2){f=false;}
			}
			if(s[i]=='.'){
				if(f && qn==0)puts("yes");
				else puts("no");
				
				fill(q,q+110,0);qn=0;
				f=true;
				
				break;
			}
		}
		
	
	}
	
	
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    string s;
    char bra[] = {'(', ')', '[', ']'};
    while(getline(cin, s) && s!=".") {
        stack<char> stk;
        bool ok = true;
        rep(i, s.size()) {
            bool is_bracket = false;
            rep(j, 4) if(s[i] == bra[j]) is_bracket = true;
            if(!is_bracket) continue;
            if(stk.empty() || s[i] == '(' || s[i] == '[') stk.push(s[i]);
            else if( (stk.top() == '(' && s[i] == ')') ||
                     (stk.top() == '[' && s[i] == ']') ) stk.pop();
            else {
                ok = false;
                break;
            }
        }

        if(ok && stk.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	while (1) {
		string input;
		getline(cin,input);
		if (input == ".") break;
		stack<char> st;
		for (auto c : input) {
			if (c == '('||c=='[') {
				st.push(c);
			}
			else if (c == ')') {
				if (st.empty()||st.top()!='(') {
					st.push('!');
					break;
				}
				else {
					st.pop();
				}
			}
			else if (c == ']') {
				if (st.empty() || st.top() != '[') {
					st.push('!');
					break;
				}
				else {
					st.pop();
				}
			}
		}
		if (st.empty()) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
}

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

int main(){
	string S;
	int n=0;
	stack<int> T[100000];
	bool hantei=true;

	while (true){
		getline(cin,S);
		hantei=true;
		if(S=="."){
			break;
		}
		for(int i=0;i<S.size();i++){
			if(S[i]=='(' || S[i]=='['){
				T[n].push(S[i]);
			}
			if(S[i]==')' || S[i]==']'){
				if(T[n].empty()){
					hantei=false;
				}
				else{
					if((T[n].top()=='(' && S[i]==']')|| (T[n].top()=='[' && S[i]==')')){
						hantei=false;
					}
					T[n].pop();
				}
			}
		}
		if(T[n].empty()==false){
			hantei=false;
		}
		cout<<(hantei?"yes":"no")<<endl;
		n++;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<stack>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	
	while(1){
		char str[111];
		gets(str);
		
		if(str[0]=='.' && strlen(str)==1)break;
		
		int valid = 1;
		stack<char> c;
		int n = strlen(str);
		rep(i,n){
			if(str[i]=='(' || str[i]=='['){
				c.push(str[i]);
			}
			if(str[i]==')' || str[i]==']'){
				if(c.empty()){
					valid=0;
					break;
				}
				char s = c.top();
				c.pop();
				
				if((str[i]==')' && s=='[')||
					(str[i]==']' && s=='(')){
					valid=0;
					break;	
				}
			}
		}
		if(!c.empty())valid=0;
		
		if(valid)puts("yes");
		else puts("no");
	}
}