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++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp*/
 
#include <iostream>
#include <stack>
 
using namespace std;

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

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

using namespace std;

int main(){
  bool flg=false,bflg;
int i;
  while(!flg){
    /*行ループ*/
    string s;
    stack<char> box;
    char ch;
    getline(cin,s);

    if(s==".")flg=true;
    else {
      /*区画ループ*/
      bflg=true;
      box.push('s');

      for(i=0;i<s.size();i++){
        ch=s.at(i);
        if(ch=='('||ch=='[')box.push(ch);
        else if(ch==')'){
          if(box.top()=='(')box.pop();
          else{
            bflg=false;
            break;
          }
        }
        else if(ch==']'){
          if(box.top()=='[')box.pop();
          else{
            bflg=false;
            break;
          }
        }
        else if(ch=='.'){
          break;
        }
      }
      if(bflg==true)cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
  }
}

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

using namespace std;

int main()
{
    string s;
    while( getline( cin, s ) ) {
        if ( s == "." )
            break;

        bool b = false;
        stack<char> t;
        t.push( '\0' );
        for( auto c : s ) {
            if ( c == '.' )
                break;

            b = [&]() mutable -> bool {
                if ( c == '(' || c == '[' )
                    t.push( c );
                else if ( c == ')' )
                    if ( t.top() == '(' )
                        t.pop();
                    else
                        return false;
                else if ( c == ']' )
                    if ( t.top() == '[' )
                        t.pop();
                    else
                        return false;
                return true;
            }();
            if ( !b )
                break;

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

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".") return;
    stack<char> st;
    int n = s.size();
    bool f = true;
    rep(i, n) {
      if (s[i] == '(') st.push('(');
      if (s[i] == '[') st.push('[');
      if (s[i] == ')') {
        if (st.size() == 0 || st.top() != '(') { f = false; break; }
        st.pop();
      }
      if (s[i] == ']') {
        if (st.size() == 0 || st.top() != '[') { f = false; break; }
        st.pop();
      }
    }
    if (!f || st.size() > 0) {
      cout << "no" << '\n';
    } else {
      cout << "yes" << '\n';
    }
  }
}

C++: #include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    
    
    
    char buf[300];
    stack<char> S;
    bool Broken;
    
    while(true){
        fgets(buf,300,stdin);
        if(buf[0] == '.' && buf[1] == '\n')break;
        
        Broken = false;
        
        for(int i = 0; buf[i] != '\0' && buf[i] != '\n'; i++){
            if(buf[i] == '('){
                S.push('(');
            }else if(buf[i] == '['){
                S.push('[');
            }else if(buf[i] == ')'){
                if(S.empty() == true || S.top() != '('){
                    Broken = true;
                    break;
                }else{
                    S.pop();
                }
            }else if(buf[i] == ']'){
                if(S.empty() == true || S.top() != '['){
                    Broken = true;
                    break;
                }else{
                    S.pop();
                }
            }
        }
        
        if(!S.empty()){
            Broken = true;
            while(!S.empty())S.pop();
        }
        
        if(!Broken)printf("yes\n");
        else{
            printf("no\n");
        }
    }
    
    return 0;
    
}

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");
  }
  0;
}