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

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;

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

int main(){

    while(true){
        string c;
        getline(cin,c);
       if(c.size()==1&&c[0]=='.'){break;}
       else{
           bool f=true;
           stack<int> m;
           rep(i,c.size()){
               if(c[i]=='('){
               m.push(1);
               }else if(c[i]==')'){
                   if(!m.empty()&&m.top()==1){
                       m.pop();
                   }else{
                      f=false;
                      break;
                   }
               }else if(c[i]=='['){
                   m.push(2);
               }else if(c[i]==']') {
                   if (!m.empty()&&m.top()==2) {
                       m.pop();
                   } else {
                       f = false;
                       break;
                   }

               }
           }
           if(!m.empty())f=false;
           if(f)cout<<"yes"<<endl;
           else cout<<"no"<<endl;
}

    }
}

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

using namespace std;

int main(void) {

  while (true) {
  string str;
  getline(cin,str);
  if (str[0] == '.') break;
  bool flag = true;
  stack<int> s;
  for (size_t i = 0; str[i] != '\0'; i++) {
    //cout << i << endl;
    int c = str[i];
    if (c == 40) {
      s.push(0);
      //cout << "push::0" << endl;
    }
    else if (c  == 91) {
      s.push(1);
      //cout << "push::1" << endl;
    }
    else if (c == 41) {
      if (s.empty()) {
	flag = false;
	break;
      }
      else {
      if (s.top() == 0) {
	s.pop();
	//cout << "pop::0" << endl;
      }
      else
	break;
      }
    }
    else if (c == 93) {
      if (s.empty()) {
	flag = false;
	break;
      }
      else {
	if (s.top() == 1) {
	  s.pop();
	//cout << "pop::1" <<endl;
	}
	else
	  break;
      }
    }
	
  }
  
  if (s.empty() && flag)
    cout << "yes" << endl;
  else
    cout << "no" << endl;

  //cout << str << endl;
  }
  return 0;

}

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

bool isYes(char input[]);

int main()
{
	char Input[101];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		if(isYes(Input)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
		if(Input[0] == '.') break;
		i++;
	}

	return 0;
}

bool isYes(char Input[])
{
	int prep[50], prepnum=0, p=3;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=0;
		} else if(Input[i] == '['){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=1;
		} else if(Input[i] == ')'){
			if(p!=0){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=1){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

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

bool isYes(char input[]);

int main()
{
	char Input[101];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		if(isYes(Input)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
		if(Input[0] == '.') break;
		i++;
	}

	return 0;
}

bool isYes(char Input[])
{
	int prep[50], prepnum=0, p=3;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=0;
		} else if(Input[i] == '['){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=1;
		} else if(Input[i] == ')'){
			if(p!=0){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=1){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

C++: #include<iostream>
#include<stack>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

main(){
  string in;
  while(getline(cin,in) && in != "."){
    stack<char> S;
    bool fg=true;
    rep(i,in.size()){
      if (in[i] == '(')S.push(in[i]);
      if (in[i] == ')'){
	if (S.empty() || S.top() != '('){fg=false;break;}
	S.pop();
      }
      if (in[i] == '[')S.push(in[i]);
      if (in[i] == ']'){
	if (S.empty() || S.top() != '['){fg=false;break;}
	S.pop();
      }
    }
    if (S.empty() && fg)cout <<"yes" << endl;
    else  cout <<"no" << endl;
  }
}

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

int main(){
  char str[100];
 
  while ( 1 ){
    string s = "yes";
    cin.getline( str, sizeof( str ) );
    if ( str[0] == '.' ) break;
    stack<char> sta;
    for ( int i = 0; str[i] != '\0'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
        sta.push( str[i] );
      }else if ( str[i] == ')' ){
        if ( sta.empty() ){
        	s = "no";
        	break;
        }
        if ( sta.top() == '(' ){
          sta.pop();
		}else{
	  		s = "no";
	  		break;
		}
      }else if ( str[i] == ']' ){
        if ( sta.empty() ){
        	s = "no";
        	break;
        }
        if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  		s = "no";
	  		break;
		}
      }
    }
    if ( !sta.empty() ) s = "no";
      cout << s << endl;
  }
}