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

int main()
{
    int tail,c1,c2;
    char str[102];
    int f[102]={0};
    char *s;
    while(true)
    {
        tail=1;
        getline(cin, str)
        if(str[0]=='.') break;
        s=str;
        c1=0; c2=0;
        for(;!(*s == '.');s++)
       {
            if(*s=='(') f[tail++]=1;
            if(*s=='[') f[tail++]=2;
            if(*s==')') if(!(f[--tail]==1)) break;
            if(*s==']') if(!(f[--tail]==2)) break;
        }
        if(tail==1 && *s == '.') cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;

int main()
{
  while(1)
    {
      string s;
      getline(cin,s);
      if(s==".") break;
      stack<char> pot;
      int sql=0,sqr=0,cil=0,cir=0;
      bool miss=false;
      bool psql=false,pcil=false;
      for(int i=0;i<s.size();i++)
	{
	  if(s[i]=='(')
	    {
	      cil++;
	      pot.push('(');
	    }
	  else if(s[i]==')') 
	    {		  
	      cir++;
	      if(pot.empty() || pot.top()!='(')
		{
		  cout << "no" << endl;
		  miss=true;
		  break;
		}
	      pot.pop();
	    }
	  else if(s[i]=='[') 
	    {
	      sql++;
	      pot.push('[');
	    }
	  else if(s[i]==']') 
	    {
	      sqr++;
	      if(pot.empty() || pot.top()!='[')
		{
		  cout << "no" << endl;
		  miss=true;
		  break;
		}
	      pot.pop();
	    }
	  if(sqr>sql || cir>cil)
	    {
	      cout << "no" << endl;
	      miss=true;
	      break;
	    }
	}
      if(!miss)
	{
	  if(sql==sqr && cil==cir)
	    {
	      cout << "yes" << endl;
	    }
	  else
	    {
	      cout << "no" << endl;
	    }
	}
    }
  return 0;
}

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

int main(){
	while(1){		
		string str;
		getline(cin, str);
		if(str[0] == '.') break;
	/*	//string::iterator ite = str.end()--;
		if(str[str.size()-1] != '.'){
			while(1){
				string s;
				cin >> s;
				str.append(s);
				//ite = s.end()--;
				if(s[s.size()-1] == '.') break;
			}
		}
*/
		stack<char> sta;
		string s = "yes";
		for(int i = 0;str[i] != '.'; 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;
	}
	return 0;
}

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>

using namespace std;

int main(){
		char a[110];
		while(fgets(a,110,stdin),*a-'.'){
				int n=strlen(a);
				if(a[n-1]=='\n')a[--n]='\0';
				int i;
				stack<int> st;
				for(i=0;i<n;i++){
						if(a[i]=='['){
								st.push(1);
						}else if(a[i]==']'){
								if(st.empty()==1){
										cout<<"no"<<endl;
										break;
								}
								if(st.top()==1){
										st.pop();
								}else{
										cout<<"no"<<endl;
										break;
								}
						}else if(a[i]=='('){
								st.push(2);
						}else if(a[i]==')'){
								if(st.empty()==1){
										cout<<"no"<<endl;
										break;
								}
								if(st.top()==2){
										st.pop();
								}else{
										cout<<"no"<<endl;
										break;
								}
						}
				}
				
				if(i==n && st.empty())cout<<"yes"<<endl;
		}
		return 0;
}

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

int main(){
  string s;
  stack<char> c;
  c.push('\0');
  while(getline(cin,s)){
    if(s == ".")break;
    while(c.size() != 1)c.pop();
    for(int i = 0;i < s.length();i++){
      if(s[i] == '(' || s[i] == '[') c.push(s[i]);		
      else if(s[i]-1 == c.top() || s[i]-2 == c.top()) c.pop();
    }
    if(c.size() == 1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

C++: //
//  main.cpp
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <stack>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[]) {
    
    
    while(1){
        string yn = "yes";
        string str;
        stack<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push(str[i]);
            }
            
            if (str[i] == ')') {
                int s = st.size();
                
                if (str[s-1] != '(') {
                    yn = "no";
                    break;
                }
                
                st.pop();
                
            }

            if (str[i] == ']') {
                int s = st.size();
                
                if (str[s-1] != '[') {
                    yn = "no";
                    break;
                }
                
                st.pop();
                
            }

        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}