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 <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

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

C++: #include <iostream>
using namespace std;
bool r(int &i,string S);
bool a(int &i,string S);
bool r(int &i,string S){
    while(i<S.size()){
        switch(S[i]){
            case '(':
                i++;
                if(!r(i,S)) return false;
                break;
            case ')':
                i++;
                return true;
            case '[':
                i++;
                if(!a(i,S)) return false;
                break;
            case ']':
                i++;
                return false;
            default:
                i++;
                break;
        }
    }
    return false;
}
 
bool a(int &i,string S){
    while(i<S.size()){
        switch(S[i]){
            case '(':
                i++;
                if(!r(i,S)) return false;
                break;
            case ')':
                i++;
                return false;
            case '[':
                i++;
                if(!a(i,S)) return false;
                break;
            case ']':
                i++;
                return true;
            default:
                i++;
                break;
        }
    }
    return false;
}
 
int main(){
    string str;
    while(true){
        getline(cin,str);
        if(str==".") return 0;
        else str.push_back(']');
        int i=0;
        if(a(i,str)&&i==str.size()){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    string s,t;
    while(1){
        bool ok=true;
        s.clear();
        t.clear();
        getline(cin,s); //改行文字まで読み込む
        /*char star;
        cin>>star;
        if(star=='.') break;
        s[0]=star;
        */
        /*while(s[s.size()-1]!='.'){
            cin>>t;
            //cout<<"t:"<<t<<endl;
            s+=t;
        }*/
        if(s=="."){
           // cout<<"break"<<endl;
            //cout<<s<<" "<<t<<endl;
            return 0;
        }
        stack<char> sc;
        //cout<<s<<endl;
        for(int i = 0;i < s.size(); i++){
            if(s[i]=='(' || s[i]=='[') sc.push(s[i]);
            else if(s[i]==')' || s[i]==']'){
                if(sc.empty()) {
                    //cout<<"here1"<<endl;
                    ok = false;
                    break;
                }
                else if(s[i]==')' && sc.top()!='('){

                    //cout<<"here2"<<endl;
                    //cout<<"s:"<<s[i]<<sc.top()<<endl;
                    ok = false;
                    break;
                }
                else if(s[i]==']' && sc.top()!='['){
                    //cout<<"here3"<<endl;
                    ok = false;
                    break;
                }
                sc.pop();
            }
        }
        //cout<<"output"<<endl;
        //cout<<"s:"<<s<<endl;
        if(ok && sc.empty()) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
  while(true){
    str text;
    getline(cin, text);
    if(text[0] == '.') break;

    stack<char> c;
    bool flag = true;
    rep(i,0,text.size()){
      if(text[i] == '(') c.push('(');
      if(text[i] == '[') c.push('[');
      if(text[i] == ')'){
        if(c.empty()){
          flag = false;
          break;
        }
        if(c.top() == '(') c.pop();
        else{
          flag = false;
          break;
        }       
      }

      if(text[i] == ']'){
        if(c.empty()){
          flag = false;
          break;
        }
        if(c.top() == '[') c.pop();
        else{
          flag = false;
          break;
        }
      }
    }
  
    if(flag && c.empty()) print("yes");
    else print("no");
  }
  
  return 0;
}

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 brackets[] = {'(', ')', '[', ']'};
    while(getline(cin, s) && s!=".") {
        stack<char> stk;
        bool yes = true;
        rep(i, s.size()) {
            bool is_bracket = false;
            rep(j, 4) if(s[i] == brackets[j]) is_bracket = true;
            if(!is_bracket) continue;
            if(s[i] == '(' || s[i] == '[') stk.push(s[i]);
            else if( (stk.top() == '(' && s[i] == ')') ||
                     (stk.top() == '[' && s[i] == ']') ) stk.pop();
            else {
                yes = false;
                break;
            }
        }

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