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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}
string tostr(char s[], int a, int n) {string res = "";for(int i=a;i<a+n;++i){if(s[i]!=0)res+=s[i];}return res;}



int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    char str[200];
    while (true) {
        memset(str, 0, sizeof(str));
        gets(str);
        
        if (str[0] == '.' && str[1] == 0) break;
        
        string kakko = "";
        for (int i = 0; i < 200; ++i) {
            if (str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']') kakko += str[i];
        }
        
        stack<char> st;
        
        for (int i = 0; i < 110; ++i) st.push('0');
        for (int i = 0; i < kakko.size(); ++i) {
            char top = st.top();
            if ((kakko[i] == ')' && top == '(') || (kakko[i] == ']' && top == '[')) {
                st.pop();
            }
            else st.push(kakko[i]);
        }
        
        if (st.top() == '0') cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    return 0;
}

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

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i]== '\n' && str[i-1]=='.') break;
        }
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

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

using namespace std;

int main()
{
	stack<char> s;

	while (true){
		char str[128];
		fgets(str, sizeof(str), stdin);

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

		bool flag = true;
		for (int i = 0; str[i] != '.'; i++){
			if (str[i] == '('){
				s.push('(');
			}
			if (str[i] == '['){
				s.push('[');
			}
			if (str[i] == ')'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '('){
					s.pop();
				}
				else if (s.top() == '['){
					flag = false;
				}
			}
			if (str[i] == ']'){
				if (s.empty()){
					flag = false;
				}
				else if (s.top() == '['){
					s.pop();
				}
				else if (s.top() == '('){
					flag = false;
					break;
				}
			}
		}

		if (flag){
			puts("Yes");
		}
		else {
			puts("No");
		}
	}

	return (0);
}

C++: #include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;
typedef pair<int,char> P;


int main(){
  string s;
  stack<P> st;
  int cc,lc;
  while(getline(cin,s) && s != "."){
    cc = 0;
    lc = 0;
    for(int i=0;i<s.length();i++)
      {
	if(s[i] == '(')
	  {
	    st.push(P('c',cc));
	    cc++;
	  }
	else if(s[i] == '[')
	  {
	    st.push(P('l',lc));
	    lc++;
	  }
	else if(s[i] == ')')
	  {
	    if(st.empty()){
	      st.push(P('v',-1));
	      break;
	    }
	    if(st.top().first == 'c')
	      {
		cc--;
		st.pop();
	      }
	    else
	      {
		break;
	      }
	  }
	else if(s[i] == ']')
	  {
	    if(st.empty()){
	      st.push(P('t',-2));
	      break;
	    }
	    if(st.top().first == 'l')
	      {
		lc--;
		st.pop();
	      }
	    else 
	      {
		break;
	      }
	  }

      }   

    if(st.empty())
      {
	cout << "yes" << endl;
      }
    else
      {
	cout << "no" << endl;
	while(st.size())
	  {
	    st.pop();
	  }
      }
  

  }



}

C++: #include <stdio.h>
#include <string.h>

#define MAX (100)

int main(void)
{
	int sp;
	char stack[MAX];
	char str[MAX + 1];
	while (1){
		int i;

		fgets(str, MAX * 2, stdin);
		if (str[0] == '.'){
			break;
		}

		sp = 0;
		for (i = 0; str[i] != '\n'; i++){
			if (str[i] == '[' || str[i] == '('){
				stack[sp++] = str[i];
			}
			else if (str[i] == ')' || str[i] == ']'){
				if (sp == 0){
					break;
				}
				char top = stack[--sp];
				if (top == '['){
					top = ']';
				}
				else {
					top = ')';
				}
				if (top != str[i]){
					break;
				}
			}
		}
	
		
		if (str[i] == '\n' && str[i - 1] == '.'){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

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

using namespace std;

string hantei(string line);

int main(void){
  string line;
  while (getline(cin, line)){
    if (line == "."){
      return 0;
    }
    cout << hantei(line) << endl;
  }
  return 0;
}

string hantei(string line){
  stack<char> left;
  queue<char> right;

  for (int i=0; i<line.size(); ++i){
    if ((line[i] == '(') || (line[i] == '[')){
      left.push(line[i]);
    }
    if (!left.empty()){
      if ((left.top() == '(') && (line[i] == ')')){
	left.pop();
      }
      else if ((left.top() == '[') && (line[i] == ']')){
	left.pop();	
      } 
    }
  }
  if (left.empty()){
    return "yes";
  }
  else{
    return "no";
  }
}