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>

class CStack
{
public:
    CStack()
    {
        topIndex = 0;
    }
    ~CStack(){;}
    
    void push(char charactor)
    {
        if(topIndex < 100)  /* スタック可能数を超えてpushした場合、なにもしない */
        {
            stack[topIndex] = charactor;
            ++topIndex;
        }
    }
    char pop(void)
    {
        if(topIndex > 0)
        {
            --topIndex;
            return stack[topIndex];
        }
        return '\0';
    }
    char top(void)
    {
        return stack[topIndex-1];
    }
    bool enpty(void)
    {
        if(topIndex == 0)
        {
            return true;
        }
        return false;
    }
    
private:
    int topIndex;
    char stack[100];
};

/* 括弧の左右が対になっているか */
bool isMatchLeftRight(char left, char right)
{
    if((left == '(') && (right == ')'))
    {
        return true;
    }
    if((left == '[') && (right == ']'))
    {
        return true;
    }
    return false;
}

/* 1行がバランスしているか */
bool isBalance(char* line)
{
    bool result = true;
    CStack cStack;      /* スタック生成 */
    
    for(int index=0; index<100; ++index)
    {
        /* 行の最後か */
        if(line[index]=='.')
        {
            break;
        }
        
        if((line[index]=='(') || (line[index]=='['))
        {
            cStack.push(line[index]);    /* 左括弧をpush */
        }
        else
        {
            if((line[index]==')') || (line[index]==']'))
            {
                if(isMatchLeftRight(cStack.top(), line[index]))
                {
                    cStack.pop();        /* 直前の左括弧をpop */
                }
                else
                {
                    result = false;
                    break;
                }
            }
        }
    }
    
    if((result==true) && (cStack.enpty()))
    {
        result = true;
    }
    else
    {
        result = false;
    }
    return result;
}

int main(void)
{
    for(;;)
    {
        std::string sLine(100, '\0');
        getline(std::cin, sLine);   /* 1行取得 */
        
        if(sLine.size()>100) /* 100文字を超えていたら終了 */
        {
            break;
        }
        if(sLine[0]=='.')    /* データセットの最後なら処理終了 */
        {
            break;
        }
        
        /* 苦肉の策 */
        char line[100] = {'\0'};
        for(int index=0; index<sLine.size(); ++index)
        {
            line[index] = sLine[index];
        }

        /* 1行がバランスしているかチェック */
        bool result = true;
        result = isBalance(line);
        
        /* 1行の結果を出力 */
        if(result == true)
        {
            std::cout << "yes" << std::endl;
        }
        else
        {
            std::cout << "no" << std::endl;
        }
    }
    return 0;
}

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

int main(){
    while(true){
        bool ju = true;
        string s;
        stack <char> box;
        getline(cin,s); if(s == ".") break;
        for(int i=0;i<s.size();i++){
            if(s[i] == '(' || s[i] == '[') box.push(s[i]);
            else if(s[i] == ')'){
                if(box.empty() || box.top()!= '(') ju = false;
            }
            else if(s[i] == ']'){
                if(box.empty() || box.top()!= '[') ju = false;
            }
            if(!ju) break;
        }
        cout << ((ju)? "yes" : "no") << endl;
    }
}

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

int main () {

  string input;

  while( true ) {

    cin >> input;

    if ( input == "." ) break;

    string s = " ";

    for ( long long int i = 0; i < input.size(); i++ ) {

      if ( input[i] == '(' ) {
	s += "(";
      }else if ( input[i] == '[' ) {
	s += "[";
      }else if ( input[i] == ')' ) {
	if ( s[ s.size() - 1 ] != '(' ) {
	  cout << "no" << endl;
	  break;
	}else {
	  s.erase( s.size() - 1 );
	}
      }else if ( input[i] == ']' ) {
	if ( s[ s.size() - 1 ] != '[' ) {
	  cout << "no" << endl;
	  break;
	}else {
	  s.erase( s.size() - 1 );
	}
      }

      if ( i == input.size() - 1 ) {
	if ( s == " " ) {
	  cout << "yes" << endl;
	}else {
	  cout << "no" << endl;
	}
      }

    }

  }

  return 0;

}

C++: #include <iostream>
#include <stack>
#include <string>
using namespace std;
int main(){
  stack<char> stack;
  string s;
  int len,i,flag;
  while(1){
    flag=0;
    getline(cin,s);
    if(s==".") break;
    len=s.size();
    for(i=0;i<len;i++){
      if(s[i]=='('||s[i]=='[') stack.push(s[i]);
      else if(s[i]==')'){
	if(stack.empty()!=true&&stack.top()=='('){
	  stack.pop();
	}
        else{
	  flag=1;
	  break;
	}
      }
      else if(s[i]==']'){
	if(stack.empty()!=true&&stack.top()=='['){
	  stack.pop();
	}
        else{
	  flag=1;
	  break;
	}
      }
    }
    if(flag==0&&stack.empty()==true){
      cout << "yes" << endl;
    }
    else{
      if(stack.empty()!=true){
	while(1){
	  stack.pop();
	  if(stack.empty()==true) break;
	}
      }
      cout << "no" << endl;
    }
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

int main(){
        char s[300];
        while(true){
                fgets(s,300,stdin);
                if(s[0]=='.'&&s[1]=='\n')return 0;
                stack<char> t;
                bool ok=false;
                for(int i=0;s[i]!='\0'&&s[i]!='\n';i++){
                        if(s[i]=='(')t.push(s[i]);
                        else if(s[i]==')'){
                                if(t.empty()||t.top()!='('){
                                        cout<<"no"<<endl;
                                        ok=true;
                                        break;
                                }
                                t.pop();
                        }
                        if(s[i]=='[')t.push(s[i]);
                        else if(s[i]==']'){
                                if(t.empty()||t.top()!='['){
                                        cout<<"no"<<endl;
                                        ok=true;
                                        break;
                                }
                                t.pop();
                        }
                }
                if(!ok){
                        if(t.empty())cout<<"yes"<<endl;
                        else cout<<"no"<<endl;
                }
        }
        return 0;
}

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

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