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;

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


int main() {
	string s;
	while (cin >> s && s != ".") {
		using P = pair<char, int>;
		queue<P> que;
		que.emplace('a', -1);
		bool ok = true;
		for (char c : s) {
			if (c == '('){ if(que.front().first == '(') que.front().second++; else que.emplace('(', 1); }
			if (c == ')'){ if(que.front().first == ')') que.front().second--; else ok = false; }
			if (c == '{'){ if(que.front().first == '{') que.front().second++; else que.emplace('{', 1); }
			if (c == '}'){ if(que.front().first == '}') que.front().second--; else ok = false; }
			if (que.front().second == 0) que.pop();
		}
		cout << (ok && que.size() == 1 ? "yes" : "no");
	}
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cctype>
#include <complex>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1<<30;
const int EPS = 1e-15;
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int > Pii;
int main(){
	while(true){
		string str;
		getline(cin,str);
		if(str.size() == 1 && str == ".")break;
		stack<char> state;
		bool flg = true;
		rep(i,str.size()){
			if(str[i] == '(' || str[i] == '['){
				state.push(str[i]);
			}
			else if(str[i] == ')'){
				if(state.size()==0 || state.top() != '('){
					flg =  false;
					break;
				}
				else{
					state.pop();
				}
			}
			else if(str[i] == ']'){
				if(state.size()==0 || state.top() != '['){
					flg =  false;
					break;
				}
				else{
					state.pop();
				}
			}
		}
		flg ? puts("yes") : puts("no");
	}
	return 0;
}

C++: # include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

template <typename T>
void show_all(T t) {
  rep (i, t.size()) {
    rep (j, t[0].size()) {
      cout << t[i][j];
    }
    cout << endl;
  }
}

int main() {
  string sentence;

  while (getline(cin, sentence)) {
    if (sentence == ".") {
      break;
    }
    int position = 0;

    stack<char> a;
    a.push('B');

    rep (i, sentence.size()) {
      if (sentence[i] == '(') a.push(sentence[i]);
      if (sentence[i] == '[') a.push(sentence[i]);

      if (sentence[i] == ')') {
        if ('(' == a.top()) a.pop();
        else {
          a.push('B');
        }
      }
      if (sentence[i] == ']') {
        if ('[' == a.top()) a.pop();
        else {
          a.push('B');
        }
      }
    }

    cout << (a.size() == 1 ? "yes" : "no") << endl;
  }
}

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

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

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

string str;

int main(){
  while( getline(cin,str) ){
    if( str[0] == '.' ) break;

    stack<char> st;

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

    if( st.empty() ) cout << "yes" << endl;
    else cout << "no" << endl;

  }
}

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

bool solve(string s)
{
    stack<char> bracket;

    for(int i=0; i < s.size(); i++)
    {
        switch(s[i])
        {
            case '(' :
            case '[' :
                bracket.push(s[i]);
                break;
            case ')' :
                if(bracket.empty() || bracket.top() != '(')
                {
                    return false;
                }
                bracket.pop();
                break;
            case ']' :
                if(bracket.empty() || bracket.top() != '[')
                {
                    return false;
                }
                bracket.pop();
                break;
            default :
                break;
        }
    } 
    
    return bracket.empty();
}

int main(void)
{
    for(;;)
    {
        string s;
        getline(cin, s);

        if (s == ".")
        {
            break;
        }
        else
        {
            cout << (solve(s) ? "yes" : "no") << endl;
        }
    }
    return 0;
}