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 <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

char s[1111];

int main(){
	while(1){
		cin.getline(s,1111);
		if(!strcmp(s, "."))return 0;
		int n=strlen(s);
		stack<char> st;
		int flag = 0;
		REP(i,n){
			if(s[i]=='('||s[i]=='[')st.push(s[i]);
			else if(s[i]==')'){
				if(!st.empty()&&st.top()=='('){
					st.pop();
				}else{
					flag = 1;
					cout << "no" << endl;
					break;
				}
			}
			else if(s[i]==']'){
				if(!st.empty()&&st.top()=='['){
					st.pop();
				}else{
					flag = 1;
					cout << "no" << endl;
					break;
				}
			}
		}
		if(flag == 1)continue;
		if(st.empty())cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };
 
 
string a;
stack<string> s;
 
int main() {
    while ( !!( getline( cin, a ) ) && a != "." ) {
        bool is_yes = true;
        for ( int i = 0; i < a.size(); i++ ) {
            if ( a[ i ] == '(' ) {
                s.push( "(" );
            }
            if ( a[ i ] == '[' ) {
                s.push( "[" );
            }
            if ( a[ i ] == ')' ) {
                if ( !s.size() || s.top() != "(" ) {
                    is_yes = false;
                    break;
                }
                s.pop();
            }
            if ( a[ i ] == ']' ) {
                if ( !s.size() || s.top() != "[" ) {
                    is_yes = false;
                    break;
                }
                s.pop();
            }
        }
        if ( is_yes && !s.size() ) {
            printf( "yes\n" );
        }
        else {
            printf( "no\n" );
        }
        while ( s.size() ) {
            s.pop();
        }
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define MAX (1000)

int main(void)
{
	int sp;
	char stack[MAX];
	char str[MAX + 1];
	while (1){
		int i;

		fgets(str, MAX, stdin);
		if (str[0] == '.'){
			break;
		}

		if (str[strlen(str) - 1] == '\n'){
			str[strlen(str) - 1] = '\0';
		}

		sp = 0;
		for (i = 0; str[i] != '\0'; i++){
			if (str[i] == '[' || str[i] == '('){
				stack[sp++] = str[i];
			}
			else if (str[i] == ')' || str[i] == ']'){
				if (sp == 0){
					break;
				}
				char top = stack[--sp];
				if (top == '['){
					top = ']';
				}
				else {
					top = ')';
				}
				if (top != str[i]){
					break;
				}
			}
		}
	
		
		if (i != 0 && str[i] == '\0'){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    getline(cin, S);
    while(S.length() - 1){
        stack<char> st;
        bool flag = 0;
        for(char c:S){
            if(c == '[' || c == '(')st.push(c);
            if(c == ']' || c == ')'){
                if(st.size() == 0){
                    flag = 1;
                    break;

                }
                char t = st.top();
                st.pop();
                if(!(t == '[' && c == ']' || t == '(' && c == ')')){
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag)cout << "YES" << endl;
        else    cout << "NO" << endl;
        getline(cin, S);
    }
}

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

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

      stack<char> stk;
      int cnt = 0;
      bool ok = false;
      int n = s.size();
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.empty() || stk.top() != '(') {
               ok = true;
               break;
            } else {
               stk.pop();
            }
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = true;
               break;
            } else {
               stk.pop();
            }
         }
      }
      if (stk.empty() && !ok) {
         puts("yes");
      } else {
         puts("no");
      }
   }
}