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

using namespace std;

int main() {
	string s;
	while (getline(cin,s)) {
		if (s == ".") {
			break;
		}
		string ss = "";
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '(') {
				ss += s[i];
			}
			if (s[i] == ')') {
				ss += s[i];
			}
			if (s[i] == '[') {
				ss += s[i];
			}
			if (s[i] == ']') {
				ss += s[i];
			}
		}
		int a, b;
		a = b = 0;
		stack<int> stk;
		bool hh = true;
		for (int i = 0; i < ss.size(); i++) {
			if (ss[i] == '(') {
				a++;
				stk.push(1);
			}
			if (ss[i] == ')') {
				a--;
				if (!stk.empty()) {
					int c = stk.top();
					stk.pop();
					if (c != 1) {
						hh = false;
						break;
					}
				}
				else {
					hh = false;
					break;
				}
			}
			if (ss[i] == '[') {
				b++;
				stk.push(2);
			}
			if (ss[i] == ']') {
				b--;
				if (!stk.empty()) {
					int c = stk.top();
					stk.pop();
					if (c != 2) {
						hh = false;
						break;
					}
				}
				else {
					hh = false;
					break;
				}
			}
		}
		if (!stk.empty()) {
			hh = false;
		}
		if (hh) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

using namespace std;

char stack[101];
int pointer;

char pop( void )
{
	if(pointer > 0) return stack[--pointer];
	else return 'x';
}
void push( char c )
{
	if(pointer < 101) stack[pointer++] = c;
}
int main( void )
{
	string in;
	while(getline(cin, in), in[0] != '.') {
		pointer = 0;
		bool hit = true;
		int len = in.size();
		for(int i=0; i < len; ++i) {
			if(in[i] == '(' || in[i] == '[') {
				push(in[i]);
			}
			else if(in[i] == ')') {
				if('(' != pop()) hit = false;
			}
			else if(in[i] == ']') {
				if('[' != pop()) hit = false;
			}
		}
		if(!pointer && hit)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;

const int INF = INT_MAX / 4;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( ui i = (ui)( m ); i < (ui)( n ); i++ )
#define EACH( v, c ) for ( __typeof( c.front() ) &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	while ( true )
	{
		string line;
		getline( cin, line );

		if ( line == "." )
		{
			break;
		}

		bool yes = true;
		char c;
		stack<char> st;
		istringstream iss( line );

		while ( iss >> c )
		{
			if ( c == '(' || c == '[' )
			{
				st.push( c );
			}
			else if ( c == ')' || c == ']' )
			{
				int c2 = ( c == ')' ? '(' : '[' );

				if ( !st.empty() && st.top() == c2 )
				{
					st.pop();
				}
				else
				{
					yes = false;
					break;
				}
			}
		}

		if ( yes )
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}				

	return 0;
}