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 <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    bool l[126] = {0};
	int i;
	char c;
	while(1){
		c = getchar();
		if(c=='.')return 0;
		i = 0;
		do{
			if(c=='('||c=='[') l[i++] = c=='[';
			if((c==')'||c==']') && (l[--i] == (c==')'))){i=-10; break;}
		}while( (c=getchar())!='.' && i>=0 &&i<126);
		if(c!='.') while(getchar()!='.');
		getchar();
		printf(i==0?"yes\n":"no\n");
	}
    return 0;
}

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

int main(void){
	char str[101];
	
	while(1){
		//入力
		gets(str);
		if(str[0]=='.')break;

		//計算
		stack<int> s;
		s.push(0);
		int flag=1;
		for(int i=0; str[i]!='.'; i++){
			if		(str[i]=='('){
				s.push(1);
			}else if(str[i]=='['){
				s.push(2);
			}else if(str[i]==')'){
				if(s.top()!=1){flag=0; break;}
				s.pop();
			}else if(str[i]==']'){
				if(s.top()!=2){flag=0; break;}
				s.pop();
			}
		}
		if(s.top()!=0){
			flag=0;
		}

		//出力
		if(flag)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	
	return 0;
}

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

using namespace std;

const int MAX=100;

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

int main(){
    while(true){
        int a=0,b=0;
        bool f = true;
        string s;
        getline(cin ,s);
        if(s[0]=='.'){break;}
        hoge(i, s.size()){
            if(s[i]=='('){a++;}
            if(s[i]==')'){a--;}
            if(s[i]=='['){b++;}
            if(s[i]==']'){b--;}
            if(a<0 || b<0){f=false; break;}
        }
        if(!(a==0&&b==0)){
            f=false;
        }

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

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
string s;
bool solve(){
  stack<char> st;
  rep(i,s.size()){
    if(s[i] == '(') st.push(s[i]);
    else if(s[i] == '[' ) st.push(s[i]);
    else if(s[i] == ')'){
      if(st.top() != '(') return false;
      if(st.empty()) return false;
      st.pop();
    }
    else if(s[i] == ']'){
      if(st.top() != '[') return false;
      if(st.empty()) return false;
      st.pop();
    }
    return st.empty();
  }
}
int main(){
  bool flag;
  while(1){
    getline(cin,s);
    if(s == ".") break;
    if(solve()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W;
long double L, R;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s;
	getline(cin, s);
	while (s != ".") {
		stack <char>st;
		bool flag = true;
		for (auto i : s) {
			if (i == '(' || i == '[') {
				st.push(i);
			}
			if (i == ')') {
				if (st.empty()) {
					flag = false;
					break;
				}
				if (st.top() == '[') {
					flag = false;
					break;
				}
				st.pop();
			}
			if (i == ']') {
				if (st.empty()) {
					flag = false;
					break;
				}
				if (st.top() == '(') {
					flag = false;
					break;
				}
				st.pop();
			}
		}
		if (flag&&st.empty()) {
			cout << "yes\n";
		}
		else {
			cout << "no\n";
		}
		getline(cin, s);
	}
	return 0;
}

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

using namespace std;

int check(char c){
  if(c == '[' || c == '(') return 2;
  if(c == ']' || c == ')') return 1;
  return 0;
}

int isOK(char c, char in){
  if(in == ']' && c == '[') return 1;
  if(in == ')' && c == '(') return 1;
  // cout << " " << c << " " << in << endl;
  return 0;
}

int main(){

  string in;
  while(getline(cin,in)){
    if(in == ".") break;
    stack<char> S;
    int status = 1;
    for(int i = 0; i < in.size(); i++){
      int j = check(in[i]);
      if(j == 2){
	S.push(in[i]);
	//	cout << " " << in[i] << endl;
      }
      if(j == 1) {
	if(S.size() == 0){
	  status = 0;
	  break;
	}
	if(!isOK(S.top(),in[i])){
	  status = 0;
	  break;
	}
	S.pop();
      }
    }
    if(status && S.size() == 0) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int strin( string );
void brackets( string, int );

int main( void )
{
    int size;
    string str;
    while( 1 )
    {
        size = 0;
        str = "";
        getline( cin, str );
        size = strin( str );
        if( 0 == size )
        {
            break;
        }
        else
        {
            brackets( str, size );
        }
    }
    return 0;
}

int strin( string str )
{
    int count = 0;
    for( int loop = 0; loop < 100; loop++ )
    {
        if( ( '.' == str[loop] ) && ( 0 == loop ) )
        {
            return 0;
        }
        else if( '.' == str[loop] )
        {
            break;
        }
        count++;
    }
    return count;
}

void brackets( string str, int size )
{
    int Parenthese = 0;
    int brackets = 0;
    char input;
    for( int loop = 0; loop < size; loop++ )
    {
        switch( str[loop] )
        {
            case '(':
                Parenthese++;
                input = str[loop];
                break;
                
            case '[':
                brackets++;
                input = str[loop];
                break;
                
            case ')':
                Parenthese--;
                if( '[' == input )
                {
                    cout << "no" << endl;
                    return;
                }
                input = str[loop];
                break;
                
            case ']':
                brackets--;
                if( '(' == input )
                {
                    cout << "no" << endl;
                    return;
                }
                input = str[loop];
                break;
                
            default:
                break;
        }
        if( ( 0 > Parenthese ) || ( 0 > brackets ) )
        {
            cout << "no" << endl;
            return;
        }
    }
    cout << "yes" << endl;
    
    return;
}