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 pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

string S;
string solve(){
    stack<char> st;
    for(auto c:S){
        if(c != '(' and c != ')' and c != '[' and c != ']') continue;
        if(c == '(' or c == '[') st.push(c);
        if(c == ')'){ if(st.empty() or st.top() != '(') return "no"; st.pop(); }
        if(c == ']'){ if(st.empty() or st.top() != '[') return "no"; st.pop(); }
    }
    return st.empty()?"yes":"no";
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(getline(cin,S)){
        if(S == ".") break;
        cout << solve() << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    map<char,char> close_of;
    close_of['('] = ')';
    close_of['['] = ']';

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

        bool ok = true;
        stack<char> stk;
        for(int i = 0; i < line.size(); ++i) {
            char c = line[i];
            if(c == '(' || c == '[') {
                stk.push(c);
            }
            else if(c == ')' || c == ']') {
                if(stk.size() == 0 || c != close_of[stk.top()]) {
                    ok = false;
                    break;
                }
                stk.pop();
            }
        }
        if(stk.size() != 0) ok = false;

        cout << (ok?"yes":"no") << endl;
    }

    return 0;
}

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

int main(void){
    int t;
    int n,m,p;
    int ans;
    string s;
    string str;
    string c;
    vector<int>x;
    while(true) {
        s="";
        while(true){
            getline(cin,str);
            s+=str;
            if(str.back()!='.')s.push_back(' ');
            else break;
        }
        if(s.front()=='.')break;
        t=0;n=0;m=0;p=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='('){t++;c.push_back(s[i]);}
            if(s[i]==')'){
                n++;
                if(c.back()=='['){cout<<"no"<<endl;goto invail;}
                else c.pop_back();
            }
            if(s[i]=='['){m++;c.push_back(s[i]);}
            if(s[i]==']'){
                p++;
                if(c.back()=='('){cout<<"no"<<endl;goto invail;}
                else c.pop_back();
            }
            if(t<n){cout<<"no"<<endl;goto invail;}
            if(m<p){cout<<"no"<<endl;goto invail;}
            //if(c.back()=='('&&s[i]==']'){cout<<"no"<<endl;goto invail;}
            //if(c.back()=='['&&s[i]==')'){cout<<"no"<<endl;goto invail;}
        }
        cout<<"yes"<<endl;
        invail:;
    }
    return 0;
}

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

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

C++: //
//  main.cpp
//  AOJ1173
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string>
#include <stack>
using namespace std;

string S;

void solve(){
    stack<char> st;
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c != '(' && c != ')' && c != '[' && c != ']')
            continue;
        
        if(c == '(' || c == '[')
            st.push(c);
        else if(c == ')' || c == ']'){
            if(st.empty()){
                cout << "no" << endl;
                return;
            }else if((st.top() == '(' && c == ']') || (st.top() == '[' && c == ')')){
                cout << "no" << endl;
                return;
            }
            st.pop();
        }
    }
    cout << "yes" << endl;
}

int main(int argc, const char * argv[])
{
    while(getline(cin, S), S!="."){
        solve();
    }
    return 0;
}