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 <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)){
    if(s==".") return 0;
    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 <cstdio>
#include <string>
#include <cstdlib>

using namespace std;
const static int STRLEN_MAX = 110;

bool analyse( string str ) {
  int i;
  int length = str.size();
  for( i = 0; i < length; i++ ) {
    if( str[ i ] == '(' ) {
      int j;
      for( j = length - 1; j > i; j-- ) {
        if( str[ j ] == ')' ) {
          int len = j - i - 1;
          return analyse( str.substr( i + 1, len ) );
        }
      }
      if( j == i ) { return false; }
    } else if( str[ i ] == '[' ) {
      int j;
      for( j = length - 1; j > i; j-- ) {
        if( str[ j ] == ']' ) {
          int len = j - i - 1;
          return analyse( str.substr( i + 1, len ) );
        }
      }
      if( j == i ) { return false; }
    }
  }
  if( i == length ) { return true; }
}


int main() {
  char str[ STRLEN_MAX ];
  int pos = 0;
  while( 1 ) {
    int c = getchar();
    if( c == '\n' || c == '\r' ) { continue; }
    str[ pos++ ] = c;
    if( c == '.' ) {
      str[ pos ] = '\0';
      if( string( str ) == "." ) { return EXIT_SUCCESS; }
      cout << ( analyse( str ) ? "yes" : "no" ) << endl;
      pos = 0;
    }
  }
}

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

using namespace std;

int main(void){
	string str;

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

		
	}
}

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

string::size_type find(char ch) {
  string sch; sch.push_back(ch);
  string tgt = "()[]";
  return tgt.find(sch);
}

int main() {
  string str;
  string s;
  
  while(getline(cin, str)) {
    if(str == ".") break;
    s.clear();
    stack<char> st;
    for(unsigned i=0; i<str.size(); i++) {
      if(find(str[i]) != string::npos) {
	s.push_back(str[i]);
      }
    }
    
    int len = s.size();
    char ch;
    
    bool ok = 1;
    for(int i=0; i<len; i++) {
      if(s[i] == '(') st.push(s[i]);
      if(s[i] == '[') st.push(s[i]);
      
      if(s[i] == ')') {
	if(st.empty()) {
	  ok = 0;
	  break;
	}

	ch = st.top();
	if(ch != '(') {
	  ok = 0;
	  break;
	}
	st.pop();
      }
      
      if(s[i] == ']') {
	if(st.empty()) {
	  ok = 0;
	  break;
	}

	ch = st.top();
	if(ch != '[') {
	  ok = 0;
	  break;
	}
	st.pop();
      }
    }
    cout << ( ok ? "yes" : "no" ) << endl;
  }
  
  return 0;
}

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

using namespace std;

int main()
{
	string s;
	int stack[100]={0};
	int pointer=0;
	bool flag=true;

	getline(cin,s);
	while (s!=".")
	{
		for (int i=0;i<s.length();++i)
		{
			if (s[i]=='(') stack[pointer++] = 1;
			if (s[i]=='[') stack[pointer++] = 2;
			if ((s[i]==')')&&(stack[--pointer]!=1)) {flag=false; break;}
			if ((s[i]==']')&&(stack[--pointer]!=2)) {flag=false; break;}
		}

		if (flag) cout<<"yes"<<endl;
		else cout<<"no"<<endl;

		flag = true;
		pointer = 0;
		getline(cin,s);
	}
}

C++: #include<iostream>
#include<stack>
main(){for(char i,f,c,s[101];fgets(s,101,stdin),s[0]-46;){std::stack<int> t;for(f=i=0;c=s[i++],c-46;){if(c==40||c==91)t.push(c);if(c==41||c==93){if(t.size()&&(c==t.top()+1||c==t.top()+2))t.pop();else f=1;}}puts(f&t.size()?"no":"yes");}}

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

int main(){
  string str;
  stack<char> s;
  int f;
  while(1){
    f=0;
    getline(cin,str);

     if(str[0]=='.') break;

    for(int i=0;i<str.size();i++){
      if(str[i]=='(' || str[i]=='[') s.push(str[i]);
      else if(str[i]==')' || str[i]==']'){
	if( s.empty()!=1 && str[i]==')' && s.top()=='(') s.pop();
	else if(s.empty()!=1 && str[i]==']' && s.top()=='[') s.pop();
	else f=1;
		    } 
    }

    if(f==0 && s.empty()==1) cout<<"yes"<<endl;
    else  cout<<"no"<<endl;
    while(s.empty()!=1)s.pop();
  }
  return 0;
}

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

int main(void) {
    string s;
    while (getline(cin, s)) {
        stack<char> paren;
        bool flag = true;
        for (auto i = 0; i < s.size(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                paren.push(s[i]);
            } else if (s[i] == ')') {
                if (!paren.empty()) {
                    char t = paren.top(); paren.pop();
                    if (t != '(') {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            } else if (s[i] == ']') {
                if (!paren.empty()) {
                    char t = paren.top(); paren.pop();
                    if (t != '[') {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            }
        }

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

    return 0;
}