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 <stack>
using namespace std;

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

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;
		stack<char> st;

		for ( auto &c : line )
		{
			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>
#include<string>

std::string str;

bool calc(int p){
	for(int i=p+1;i<str.size();i++){
		if(str[i]=='('){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==')'){
			if(str[p]=='(')return true;
			else return false;
		}
		if(str[i]=='['){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==']'){
			if(str[p]=='[')return true;
			else return false;
		}
	}
	return false;
}

int main(){
	while(1){
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				if(!calc(i)){
					std::cout<<"no";
					goto end;
				}
				break;
			}
		}
		std::cout<<"yes";
		end:;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
	while(1){
		bool flag;
		flag = true;
		string str;
		stack<int> num;
		getline(cin,str);
		if(str==".")	break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='[')	num.push(1);
			else if(str[i]==']'){
				if(num.size()==0){
					flag=false;
					break;
				}
				if(num.top()==1)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]==')'){
				if(num.size()==0){
					flag = false;
					break;
				}
				if(num.top()==2)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]=='(')	num.push(2);
			
		}
		if(num.size()==0&&flag)	cout << "yes\n";
		else	cout << "no\n";
	}
}

C++: #include <iostream>
#include <stack>
#include <vector>
using namespace std;

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

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)(N);i++)
#define ck(n,a,b) (a)<=(n)&&(n)<=(b)
#define p(s) cout<<(s)<<endl
#define F first
#define S second
typedef long long ll;
using namespace std;

int main() {

	while(1){
		//int ind=0;
		char s[110]={};
		scanf("%c",&s[0]);
		if(s[0]=='\n') continue;
		if(s[0]=='.'){
			break;
		}
		int ind=0;
		while(s[ind]!='.'){
			ind++;
			scanf("%c",&s[ind]);
		}
		bool flag=true;
		stack<char> st;
		int i=0;
		while(s[i]!='.'){
			if(s[i]=='('||s[i]=='['){
				st.push(s[i]);
			}
			else if(s[i]==')'){
				if(!st.empty()&&st.top()=='('){
					st.pop();
				}else flag=false;
			}else if(s[i]==']'){
				if(!st.empty()&&st.top()=='['){
					st.pop();
				}else flag=false;
			}
			if(!flag) {
				break;
			}
			i++;
		}
		if(!st.empty()) flag=false;
		p(flag?"yes":"no");

	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

int main(void){
    string s;
    while(getline(cin, s) && s!=".") {
        int rb=0, sb=0;
        bool ok = true;
        int l, r=s.size()-1;
        for(int l=0; l<r; l++) {
            if(s[l] == '(') {
                for(; r>=0 && s[r]!=')'; r--) ;
                if(r < l) {
                    ok=false;
                    break;
                }
            }
            if(s[l] == '[') {
                for(; r>=0 && s[r]!=']'; r--) ;
                if(r < l) {
                    ok=false;
                    break;
                }
            }
        }
        if(ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}