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 <stack>
using namespace std;

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

C++: import java.util.*;class Main{public static void main(String[]a){int i=0;Scanner s=new Scanner(System.in);for(;;){String t=s.nextLine(),r="";if(t.equals("."))break;for(char c:t.toCharArray()){i="()[]".indexOf(c);r+=i<0?"":i;}for(;i<99;i++)r=r.replace("01","").replace("23","");System.out.println(r.equals("")?"yes":"no");}}}

C++: #include <iostream>
#include <stack>
#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;

  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";
  }
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359

int main(void) {
  vector<string> ans;
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".")
      break;
    stack<int> st;
    bool flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(')
        st.push(1);
      else if (s[i] == '[')
        st.push(2);
      else if (s[i] == ')') {
        if (!st.empty() && st.top() == 1)
          st.pop();
        else {
          flag = false;
          break;
        }
      } else if (s[i] == ']') {
        if (!st.empty() && st.top() == 2)
          st.pop();
        else {
          flag = false;
          break;
        }
      }
      /*
      stack<int> debug;
      debug = st;
      while (!debug.empty()) {
        cout << debug.top() << " ";
        debug.pop();
      }
      cout << endl; */
    }
    if(!st.empty()) flag = false;
    if (flag) {
      ans.push_back("yes");
    } else {
      ans.push_back("no");
    }
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

string s;

int main()
{
  while(getline(cin, s) && s != "."){
    deque<char> l;
    deque<char> r;
    vrep(v, s){

      if(*v == '(' || *v == '[') l.push_back(*v);
      if(*v == ')' || *v == ']') r.push_front(*v);
      if(l.size() < r.size()) break;
      if(l.empty() || r.empty()) continue;
      if(l.back() == '(' && r.back() == ')' || l.back() == '[' && r.back() == ']'){
        l.pop_back();
        r.pop_front();
      }
    }

    if(l.size() == r.size()){
      while(!l.empty()){
        if(l.front() == '(' && r.front() == ')' || l.front() == '[' && r.front() == ']'){
          l.pop_front();
          r.pop_front();
        }
        else break;
      }
    }

    puts(l.empty() && r.empty() ? "yes" : "no");
  }

  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(void) {
	string input;
	while(1) {
		getline(cin, input);
		if(input == ".") {
			break;
		}

		vector<char> sign;
		for(int i = 0; i < input.size(); i++) {
			if(input[i] == '(') {
				sign.push_back('(');
			}
			if(input[i] == '[') {
				sign.push_back('[');
			}
			if(input[i] == ')') {
				if(sign.empty()) {
					sign.push_back(')');
					break;
				}else if(*(sign.end() - 1) != '(') {
					break;
				}
				sign.pop_back();
			}
			if(input[i] == ']') {
				if(sign.empty()) {
					sign.push_back(']');
					break;
				}else if(*(sign.end() - 1) != '[') {
					break;
				}
				sign.pop_back();
			}
		}

		if(sign.empty()) {
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	return 0;
}

C++: #include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, b, e) for (typeof(b) i = (b); assert((i) <= (e)), i != (e); ++i)
#define SZ(a) ((int)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define BIT(n) (1ULL << (n))

static const double PI (3.14159265358979323846);
static const double EPS (1e-10);

using namespace std;
typedef long long int LL;
typedef pair<int,int> P;/*}}}*/

int main(int argc, char const* argv[])
{
	string str;
	while (getline(cin, str)) {
		if (str == ".") {
			break;
		}
		stack<char> st;
		FOR(i, 0, str.length()) {
			switch (str.at(i)) {
				case '(':
					st.push('(');
					break;
				case '[':
					st.push('[');
					break;
				case ')':
					if (st.empty() || st.top() != '(') {
						goto NO;
					}
					st.pop();
					break;
				case ']':
					if (st.empty() || st.top() != '[') {
						goto NO;
					}
					st.pop();
					break;
			}
		}
		if (!st.empty()) {
			goto NO;
		}
		cout << "yes" << endl;
		continue;
NO:
		cout << "no" << endl;
	}
	return 0;
}