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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  string s;
  while(getline(cin,s),s!=".")
  {
    stack<char> t;
    bool judge=true;
    rep(i,s.size())
    {
      if(s[i]=='('||s[i]=='[') t.push(s[i]);
      else if((s[i]==')'||s[i]==']'))
      {
        if(t.empty())
        {
          judge=false;
          break;
        }
        else if(s[i]==')'&&t.top()=='(') t.pop();
        else if(s[i]==']'&&t.top()=='[') t.pop();
        else 
        {
          judge=false;
          break;
        }
      } 
    }
    if(!t.empty()) judge=false;
    if(judge) print("yes");
    else print("no");

  }

  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main()
{
	while(1) {
		string s;
		getline(cin, s);
		if (s.size() == 1 && s[0] == '.') break;

		string a;
		rep(i,0,s.size()) {
			if (s[i] == '(') a += '(';
			if (s[i] == ')') a += ')';
			if (s[i] == '[') a += '[';
			if (s[i] == ']') a += ']';
		}
		//debug(a);
		while (a.size() >= 2) {
			bool update = false;
			rep(i,0,a.size()-1) {
				if ((a[i] == '(' && a[i+1] == ')') || (a[i] == '[' && a[i+1] == ']')) {
					a = a.substr(0,i) + a.substr(i+2); 
					update = true;
					//debug(a);
				}
				else if (i == a.size()-2 && update == false) a = "x";
				if (a.size() < 2) break;
			}
		}

		if (a.size() == 0) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

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

stack<char> st;

string::size_type find(char ch) {
  string sch; sch.push_back(ch);
  string tgt = "()[]";
  return tgt.find(sch);
}

int main() {
  string str;
  string s;
  
  while(getline(cin, str)) {
    if(str == ".") break;
    s.clear();
    for(unsigned i=0; i<str.size(); i++) {
      if(find(str[i]) != string::npos) {
	s.push_back(str[i]);
      }
    }
    
    int len = s.size();
    char ch;
    
    bool ok = 1;
    for(int i=0; i<len; i++) {
      if(s[i] == '(') st.push(s[i]);
      if(s[i] == '[') st.push(s[i]);
      
      if(s[i] == ')') {
	ch = st.top();
	if(ch != '(' || !i) {
	  ok = 0;
	  break;
	}
	st.pop();
      }
      
      if(s[i] == ']') {
	ch = st.top();
	if(ch != '[' || !i) {
	  ok = 0;
	  break;
	}
	st.pop();
      }
    }
    cout << ( ok ? "yes" : "no" ) << endl;
  }
  
  return 0;
}

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

void replaceAll(string &s,string from,string to){
	int pos=s.find(from);
	for(;pos!=string::npos;pos=s.find(from)){
		s.replace(pos,from.size(),to);
	}
}
void solve(){
	string s="";
	for(string::iterator it=str.begin();it!=str.end();it++){
		if((*it)=='('||(*it)==')'||(*it)=='['||(*it)==']')s+=(*it);
	}
	while(s!=""){
		string _s=s;
		if(s[0]==')'||s[0]==']')break;
		replaceAll(s,"()","");
		replaceAll(s,"[]","");
		if(s==_s)break;
	}
	if(s=="")cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}
int main(){
	while(getline(cin,str)&&str[0]!='.'){
		solve();
	}

	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    while(true){
        getline(cin, s);
        if(s[0] == '.') break;
        int len = s.size();
        int rb = 0, sb = 0;
        bool ok = true;
        stack<char> brs;
        for(int i = 0; i < len; i++){
            if(s[i] == '('){
                brs.push('(');
            }else if(s[i] == ')'){
                if(brs.empty() || brs.top() != '('){
                    ok = false;
                    break;
                }
                brs.pop();
            }else if(s[i] == '['){
                brs.push('[');
            }else if(s[i] == ']'){
                if(brs.empty() || brs.top() != '['){
                    ok = false;
                    break;
                }
                brs.pop();
            }
        }
        if(ok){
            puts("yes");
        }else{
            puts("no");
        }
    }
    return 0;
}