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

using namespace std;


string words;

void solve(){
  stack<char> st;
  for(int i = 0; '.' != words[i];i++){
    if(words[i] == '(' || words[i] == '['){
      st.push(words[i]);
    }else if(words[i] == ')'){
      if(!st.empty()){
        if(st.top() == '('){
          st.pop();
        }else{
          cout << "no" << endl;
          return;
        }
      }else{
        cout << "no" << endl;
        return;
      }
    }else if(words[i] == ']'){
      if(!st.empty()){
        if(st.top() == '['){
          st.pop();
        }else{
          cout << "no" << endl;
          return;
        }
      }else{
        cout << "no" << endl;
        return;
      }
    }
  }
  if(st.empty()) cout << "yes" << endl;
  return;
}




int main(){
  while(true){
    words = "";
    //string x;
    getline(cin , words);
    //cin >> x;
    //cout << words << endl;
    if(words == '.') break;
    solve();
  }
  return 0;
}

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

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	cin.tie(0); //対話型には使えない
	ios::sync_with_stdio(false); //printfと共には使えない
	string str;
	while (str = "", getline(cin, str), str != ".") {
		stack<char> s;
		REP(i, str.size()) {
			if (str[i] == '[' || str[i] == '(') {
				s.push(str[i]);
			} else if (str[i] == ']') {
				if (s.size() == 0 || s.top() != '[') {
					PRINT("no");
					break;
				}
				s.pop();
			} else if (str[i] == ')') {
				if (s.size() == 0 || s.top() != '(') {
					PRINT("no");
					break;
				}
				s.pop();
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

C++: #include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<sstream>
#include<complex>
#include<fstream>
#include<bitset>
#include <iostream>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i,N) for(int i=0;i<(N);i++)

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

C++: #include<iostream>
using namespace std;
int main()
{
	int q,p;
	q=p=0;
	char a;
	while(a = getchar())
	{if(a=='\n')
		if(q==p&&q==0){
			cout<<"yes"<<endl; q=p=0;
		}
		else{
			cout<<"no"<<endl; q=p=0;
		}
		
	else if(a=='(') q++;
	else if(a==')')q--;
	else if(a=='[')p++;
	else if(a==']')p--;
	}
}

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

using namespace std;

string hantei(string line);

int main(void){
  string line;
  while (getline(cin, line)){
    if (line == "."){
      return 0;
    }
    cout << hantei(line) << endl;
  }
  return 0;
}

string hantei(string line){
  stack<char> left;
  queue<char> right;

  for (int i=0; i<line.size(); ++i){
    if ((line[i] == '(') || (line[i] == '[')){
      left.push(line[i]);
    }
    if (!left.empty()){
      if ((left.top() == '(') && (line[i] == ')')){
	left.pop();
      }
      else if ((left.top() == '[') && (line[i] == ']')){
	left.pop();	
      } 
    }
  }
  if (left.empty()){
    return "yes";
  }
  else{
    return "no";
  }
}

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 == "." )
		{
			return 0;
		}

		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;
				}
			}
		}

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

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int tail,c1,c2;
    char str[102];
    int f[102]={0};
    char *s;
    while(1){
        tail=1;
        fgets(str,102,stdin);
        if(str[0]=='.') break;
        s=str;
        c1=0; c2=0;
        for(;!(*s == '.');s++){
            if(*s=='(') f[tail++]=1;
            if(*s=='[') f[tail++]=2;
            if(*s==')') if(!(f[--tail]==1)) break;
            if(*s==']') if(!(f[--tail]==2)) break;
        }
        if(tail==1 && *s == '.') cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}