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<string>
#include<stack>
#include<map>
using namespace std;

map<char,char> m;
stack<char> st;	



void check(string str){
	for(int i=0;i<str.size();i++){
		if(
			str[i]=='(' ||
			str[i]=='[' ||
			str[i]=='{'
		){
			st.push(str[i]);
		} else if(
			str[i]==')' ||
			str[i]==']' ||
			str[i]=='}'					
		){
			if(!st.empty()){
				if(m[st.top()]==str[i]){
					st.pop();
				}
			}
		}
	}
}

bool isPeriod(string str){
	for(int i=0;i<str.size();i++){
		if(str[i]=='.') return true;
	}
	return false;
}

int main(){
	m['(']=')';
	m['[']=']';
	m['{']='}';
	string str;
	while(1){
		getline(cin,str);
		if(!str.compare(".")) break;
		check(str);
		if(isPeriod(str)){
			if(st.empty()){
				cout << "yes" << endl;
			}else {
				cout << "no" << endl;
			}
			while(!st.empty()){
				st.pop();
			}
		}

	}
	return 0;
}

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

int main(void){
  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;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void test(int );
int f;
char ch[101]; 
int main(){
  while(1){
    int j=0;
    while(1){
      scanf("%c",&ch[j]);
      if(ch[j]=='.')break;
      j++; 
    }
    if(j==0)break;
    int count=0,count1=0;
    for(int i=0;i<j;i++){
      if(count1<0||count<0||f==1)break; 

      if(ch[i]=='[')count++;
      else if(ch[i]=='(')count1++;
      else if(ch[i]==']')test(i);
      else if(ch[i]==')')test(i);
    }
    if(count==0&&count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char a;
    scanf("%c",&a);
  }
  return 0;
}
void test(int x){
  f=0;
  int count2;
  if(ch[x]==')'){
    count1--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='('){
	count2=0;
	for(int j=x-1;j>i;i++)
	  if(ch[i]=='[')count2++;
	  else if(ch[i]==']')count2--;
	if(count2>=1)f=1;
      }
  }
  else{
    count--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='['){
	count2=0;
	for(int j=x-1;j>i;i++)
	  if(ch[i]=='(')count2++;
	  else if(ch[i]==')')count2--;
	if(count2>=1)f=1;
      }
  }
}

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

int main()
{
  string str;

  while (getline(cin,str))
  {
    if (str == ".") return 0;

    int paren = 0;
    int blacket = 0;
    stack<char> p;
    bool flag = true;

    for (int i=0;i<str.length();i++)
    {
      if (str[i] == '(')
      {
        paren++;
        p.push('(');
      }
      else if (str[i] == ')')
      {
        paren--;
        if (paren < 0) { flag = false; break; }
        if (p.top() != '(') { flag = false; break; }
        p.pop();
      }
      else if (str[i] == '[')
      {
        blacket++;
        p.push('[');
      }
      else if (str[i] == ']')
      {
        blacket--;
        if (blacket < 0) { flag = false; break; }
        if (p.top() != '[') { flag = false; break; }
        p.pop();
      }
    }
    if (flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <iomanip>
#include <cassert>
using namespace std;

int main(){
    while(true){
        char s[12800];
        if(scanf("%[^.]", s) == EOF) break;
        int len = strlen(s);
        bool ok = true;
        stack<char> left_br;
        for(int i = 0; i < len; i++){
            if(s[i] == '('){
                left_br.push('(');
            }else if(s[i] == ')'){
                if(left_br.empty() || left_br.top() != '('){
                    ok = false;
                    break;
                }
                left_br.pop();
            }else if(s[i] == '['){
                left_br.push('[');
            }else if(s[i] == ']'){
                if(left_br.empty() || left_br.top() != '['){
                    ok = false;
                    break;
                }
                left_br.pop();
            }
        }
        if(ok){
            puts("yes");
        }else{
            puts("no");
        }
        scanf("%[\n.]");
    }
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(getline(cin,s)){
    if(s == ".") break;
    bool f = true;
    stack<char> st;
    rep(i,s.size()){
      if(s[i] == '('){
        st.push('(');
      }
      if(s[i] == ')'){
        if(! st.size() || (st.size() && st.top() != '(')) f = false;
        if(st.size())st.pop();
      }
      if(s[i] == '['){
        st.push('[');
      }
      if(s[i] == ']'){
        if(! st.size() || (st.size() && st.top() != '[')) f = false;
        if(st.size())st.pop();
      }
    }
    if(f){
      cout << "yes"<<endl;
    }
    else{
      cout << "no"<<endl;
    }
  }
  return 0;
}