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 <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
		string data;
	while(getline(cin, data) && data != ".") {
		// 1=(, 2=), 3=[, 4=]
		int v[100]={0}, c=0, size=data.size();
		for (int i=0; i<size; i++) {
			if (data[i] == '(') {
				v[c]=1; c++;
			}else if (data[i] == '[') {
				v[c]=2; c++;
			}else if (data[i] == ')') {
				if (v[c-1] == 1) {
					v[c-1]=0; c--;
				}
			}else if (data[i] == ']') {
				if (v[c-1] == 2) {
					v[c-1]=0; c--;
				}
			}
		}
		if (v[0] == 0) cout << "yes\n";
		else cout << "no\n";
	}
}

C++: #include<iostream> 
#include<cstdio> 
#include<string> 
using namespace std; 
void test(int ); 
int f,count,count1; 
string str,s;  

int main(){ 
  while(1){ 
    f=0,count=0,count1=0;
    s.clear();
    while(1){
      getline(cin,str);
      s+=str;
      if(s[s.size()-1]=='.')break;
    }
    int slen=s.size();
    if(s==".")break;

    for(int i=0;i<slen;i++){ 
      if(s[i]=='[')count++; 
      else if(s[i]=='(')count1++; 
      else if(s[i]==']' || s[i]==')')test(i); 
      if(count1<0||count<0||f==1)break;  
    } 
    if(count==0&&count1==0)cout<<"yes"<<endl; 
    else cout<<"no"<<endl;   
  } 
  return 0; 
} 

void test(int x){ 
  f=0; 
  int count2=0; 
  if(s[x]==')'){ 
    count1--; 
    for(int i=x-1;i>=0;i--) 
      if(s[i]=='('){ 
	for(int j=x-1;j>i;j--) 
	  if(s[j]=='[')count2++; 
	  else if(s[j]==']')count2--; 
	break; 
      } 
  } 
  else if(s[x]==']'){ 
    count--; 
    for(int i=x-1;i>=0;i--) 
      if(s[i]=='['){ 
	for(int j=x-1;j>i;j--) 
	  if(s[j]=='(')count2++; 
	  else if(s[j]==')')count2--; 
	break; 
      } 
  } 
  if(count2>0)f=1; 
}

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()
{
	bool cont = true;

	while ( cont )
	{
		bool yes = true, first = true;
		char c;
		stack<char> st;

		while ( cin >> c )
		{
			if ( c == '.' )
			{
				if ( first )
				{
					cont = false;
				}

				break;
			}

			first &= false;

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

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

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

	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  while(getline(cin,s)){
    stack<int> ss;
    for(int i=0;i<s.length();i++){
      if(s[i]=='('){
        ss.push(0);
      }else if(s[i]=='['){
        ss.push(1);
      }else if(s[i]==')'){
        if(ss.empty()){
          cout << "no" << endl;
          goto next;
        }
        if(ss.top()==0){
          ss.pop();
        }else{
          cout << "no" << endl;
          goto next;
        }
      }else if(s[i]==']'){
        if(ss.empty()){
          cout << "no" << endl;
          goto next;
        }
        if(ss.top()==1){
          ss.pop();
        }else{
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << "yes" << endl;
    next:
    continue;
  }
  return 0;
}

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

using namespace std;

int main()
{
    for (;;) {
        string str;
        getline(cin, str);
        if (str == ".")
            break;

        stack<int> s;
        string::iterator i;
        for (i = str.begin(); i != str.end(); ++i) {
            if (*i == '(') {
                s.push(1);
            } else if (*i == ')') {
                if (!s.empty() && s.top() == 1)
                    s.pop();
                else
                    break;
            } else if (*i == '[') {
                s.push(2);
            } else if (*i == ']') {
                if (!s.empty() && s.top() == 2)
                    s.pop();
                else
                    break;
            }
        }
        if (i == str.end() && s.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}

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

using namespace std;

bool solve(string S)
{
	stack<char> s;

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '(' || S[i] == '[')
		{
			s.push(S[i]);
		}

		if (S[i] == ')' || S[i] == ']')
		{
			if (s.empty()) { return false; }

			if (s.top() != (S[i] == ')' ? '(' : '['))
			{
				return false;
			}
			
			s.pop();
		}
	}

	return s.empty();
}

int main()
{
	string S;

	while (true)
	{
		S = "";

		while (S == "")
		{
			getline(cin, S);
		}

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

		cout << (solve(S) ? "yes" : "no") << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main()
{
  string str;
  int i;
  while(true){
    getline(cin, str);
    if(str[0] == '.') break;
    
    int len = 0;
    while(str[len] != '\0'){
      len++;
    }
        
    int d[101] = {0}, j;
    for(i = 0, j = 0 ; i < len ; i++){
      if(str[i] == '('){
	d[++j] = 1;
      }
      if(str[i] == '['){
	d[++j] = 2;
      }
      if(str[i] == ')'){
	if(d[j--]-1){
	  break;
	}
      }
      if(str[i] == ']'){
	if(d[j--]-2){
	  break;
	}
      }
    }
    if(str[i] || j){
      cout << "no" << '\n';
    }else{
      cout << "yes" << '\n';
    }
  }
}