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<string.h>
#include<string>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  while(1){
    stack<int> sta;//[]:1 ():2 
    bool ans=true;
    char c[150];
    gets(c);
    if(c[0]=='.')break;
    else if(c[0]=='[')sta.push(1);
    else if(c[0]=='(')sta.push(2);
    else if(c[0]==']' || c[0]==')')ans=false;
    int i=0;
    while(ans){
      i++;
      // printf("c='%c'\n",c[i]);
      if(c[i]=='[')sta.push(1);
      else if(c[i]=='(')sta.push(2);
      else if(c[i]==']')
	if(sta.size() && sta.top()==1)sta.pop();
	else{
	  ans=false;
	  break;
	}
      else if(c[i]==')')
	if(sta.size() && sta.top()==2)sta.pop();
	else{
	  ans=false;
	  break;
	}
      else if(c[i]=='.')break;
    }
    if(sta.size()==0 && ans)cout<<"yes"<<endl;
    else{
      cout<<"no"<<endl;
    }
  }


}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void test(int );
int f,count,count1;
char ch[101]; 
int main(){
  while(1){
    int j=0;
    while(1){
      scanf("%c",&ch[j]);
      if(ch[j]=='.')break;
      j++; 
    }
    if(j==0)break;
    count=0,count1=0;

    for(int i=0;i<j;i++){
      if(ch[i]=='[')count++;
      else if(ch[i]=='(')count1++;
      else if(ch[i]==']' || ch[i]==')')
	test(i);
      if(count1<0||count<0||f==1)break; 
    }

    if(count==0&&count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char a;
    scanf("%c",&a);
  }
  return 0;
}

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

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

#define loop(lp) for(int i = 0;i < lp;i++)

using namespace std;       
int main(){
  string s;
  stack<int> a;
  int i=0,j;
  while(getline(cin,s)){
    while(s[i] != '.'){
      
      if(s[i] == '('){
	a.push('(');  
      }else if(s[i] == ')'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '('){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }else if(s[i] == '[' ){
	a.push('[');  
      }else if(s[i] == ']'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '['){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }
      i++;
    }
    if(i == 0){
      break;
    }
    if(a.size() == 0 && j != 1){
	cout << "yes" <<endl;
      }else{
	cout<<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
    
    
    return 0;
}

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

using namespace std;

int main()
{
  int end;
  stack <char> sta;

  while(1){
    string v;
    string l;
    string g;
    end = 0;

    while(1){
      cin>>v;
      l = l+v;

      for(auto s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

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

    for(auto e : l){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        auto t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        auto t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }

    if(g != "no"){
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

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

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

int main(){
    string in;
    while( getline(cin, in), !(in.length()==1 && in[0]=='.') ) {
        stack<int> brackets;
        bool judge = true;
        rep( i, in.length() ) {
            if( in[i] == '(' ) {
                brackets.push(0);
            } else if( in[i] == '[' ) {
                brackets.push(1);
            } else if( in[i] == ')' ) {
                if( !(brackets.size()>0 && brackets.top()==0) ) {
                    judge = false;
                } else {
                    brackets.pop();
                }
            } else if( in[i] == ']' ) {
                if( !(brackets.size()>0 && brackets.top()==1) ) {
                    judge = false;
                } else {
                    brackets.pop();
                }
            }
        }
        cout << (judge ? "yes" : "no") << endl;
    }
    return 0;
}

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

using namespace std;

template<typename Iter>
Iter ss( Iter it, Iter const end, typename Iter::value_type const c )
{
    for( ; it<end; ++it ) {
        if ( *it == c )
            return it;
        if ( *it == '(' )
            if ( ( it = ss( it+1, end, ')' ) ) == end )
                break;
        if ( *it == '[' )
            if ( ( it = ss( it+1, end, ']' ) ) == end )
                break;
    }
    return end;
}

template<typename Range>
bool ff( Range const& r )
{
    for( auto it=r.cbegin(); it<r.cend()&&*it!='.'; ++it ) {
        if ( *it == ')' || *it == ']' )
            return false;
        if ( *it == '(' )
            if ( ( it = ss( it+1, r.cend(), ')' ) ) == r.cend() )
                return false;
        if ( *it == '[' )
            if ( ( it = ss( it+1, r.cend(), ']' ) ) == r.cend() )
                return false;
    }
    return true;
}



int main()
{
    string s;
    while( getline( cin, s ) ) {
        if ( s == "." )
            break;
        cout << ( ff( s ) ? "yes" : "no" ) << endl;
    }
}

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

const char a[] = {'(', '['};
const char b[] = {')', ']'};

int main () {
    string str;
    while (getline(cin, str), str.size()) {
        stack<char> s;
        bool ans = true;
        for (int i = 0; i < str.size(); i++) {
            if ('a' > str[i] || str[i] > 'z') {
                if (str[i] == a[0] || str[i] == a[1]) {
                    s.push(str[i]);
                } else if (str[i] == b[0] || str[i] == b[1]) {
                    if (s.empty()) {
                        ans = false; break;
                    } else if (str[i] == b[0] && s.top() == a[0]) {
                        s.pop();
                    } else if (str[i] == b[1] && s.top() == a[1]) {
                        s.pop();
                    } else {
                        ans = false; break;
                    }
                }
            }
        }
        if (s.size() != 0) ans = false;

        cout << (ans ? "yes" : "no") << endl;
    }

    return 0;
}