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;

char str[128];
stack<char> st;

int main(){
	while(1){
		memset(str,0,sizeof(str));
		fgets(str,sizeof(str),stdin);
		if(str[0] == '.' && (str[1] == '\0' || (str[1] == '\n' && str[2] == '\0'))){
			break;
		}
		st = stack<char>();
		st.push('*');
		bool ok = true;
		for(int i = 0; i < sizeof(str) && ok; i++){
			switch(str[i]){
				case '(' :
					st.push('(');
					break;
				case ')' :
					if(st.top() == '('){
						st.pop();
					}
					else{
						ok = false;
					}
					break;
				case '[' :
					st.push('[');
					break;
				case ']' :
					if(st.top() == '['){
						st.pop();
					}
					else{
						ok = false;
					}
					break;
				default :
					break;
			}
		}
		if(ok && st.top() == '*'){
			puts("yes");
		}
		else{
			puts("no");
		}

	}

	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char s[1000];
int main(){
	while(1) {
		fgets(s,500,stdin);
		int n = strlen(s);
		n--;
		if(n == 1 && s[0] == '.') {
			break;
		}


		stack<int> last;

		bool f = true;int rb = 0,sb = 0;
		REP(i,n) {
			if(!last.empty() && last.top() == 0 && s[i] == ']') {
				f = false;
				break;
			}
			if(!last.empty() && last.top() == 1 && s[i] == ')') {
				f = false;
				break;
			}
			if(s[i] == ')') {
				rb--;
				last.pop();
				if(rb < 0) {
					f = false;
					break;
				}
			}
			if(s[i] == ']') {
				sb--;
				last.pop();
				if(sb < 0) {
					f = false;
					break;
				}
			}
			if(s[i] == '(')  {
				rb++;
				last.push(0);
			}
			if(s[i] == '[')  {
				sb++;
				last.push(1);
			}
		}
		if(!last.empty()) {
			f = false;
		}
		if(f) {
			cout << "yes" << endl;
		}else {
			cout << "no" << endl;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[1000];
int main() {
  while (fgets(str, stdin), str[0] != '.') {
    stack<int> st;
    int len = strlen(str);
    bool ok = true;
    REP(i, len) {
      if (str[i] == '(') { st.push('('); }
      else if (str[i] == '[') { st.push('['); }
      else if (str[i] == ')') {
        if (st.empty() || st.top() != '(') { ok = false; break; }
        st.pop();
      } else if (str[i] == ']') {
        if (st.empty() || st.top() != '[') { ok = false; break; }
        st.pop();
      }
    }
    if (!st.empty()) { ok = false; }
    puts(ok ? "yes" : "no");
  }
}

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

using namespace std;

int main(void) {
  string s;
  while (getline(cin, s) && s != ".") {
    int ssz = s.size();
    stack<char> st;
    bool flag = true;
    for (int i = 0; i < ssz; i++) {
      if (s[i] == '(' || s[i] == '[') st.push(s[i]);
      else if (s[i] == ')') {
        if (st.empty() || st.top() != '(') {
          flag = false;
          continue;
        }
        st.pop();
      } else if (s[i] == ']') {
        if (st.empty() || st.top() != '[') {
          flag = false; 
          continue;
        }
        st.pop();
      }
    }
    if (st.size()) flag = false;

    if (flag) cout << "yes\n";
    else cout << "no\n";
  }

  return 0;
}

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

using namespace std;

string s;
vector<bool> out;

int main(){
	do{
		s.clear();
		do{
			string temp;
			getline(cin,temp);
			s+=temp;
		}while(s[s.length()-1]!='.');
		if (s.length()!=1){
			stack<int> st;	//(=0,[=1;
			int i=0,l=s.length();
			for (;i<l;i++){
				if (s[i]=='('){
					st.push(0);
				}
				else if (s[i]=='['){
					st.push(1);
				}
				else if (s[i]==')'){
					if (st.empty){
						out.push_back(false);
						break;
					}
					int type=st.top();
					st.pop();
					if (type!=0){
						out.push_back(false);
						break;
					}
				}
				else if (s[i]==']'){
					if (st.empty()){
						out.push_back(false);
						break;
					}
					int type=st.top();
					st.pop();
					if (type!=1){
						out.push_back(false);
						break;
					}
				}
			}
			if (i==l){
				if (st.empty()){
					out.push_back(true);
				}
				else{
					out.push_back(false);
				}
			}
		}
	}while(s.length()!=1);
	for (int i=0;i<out.size();i++){
		printf("%s\n",out[i] ? "yes" : "no");
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		stack<char> st;
		bool flag = true;
		for(char c : s){
			if(c == '(' || c == '[') st.push(c);
			else if(c ==')') {
				if(st.empty() || st.top() != '(') {
					flag =false;
					break;
				}
				st.pop();
			} 
			else if(c ==']') {
				if(st.empty() || st.top() != '[') {
					flag =false;
					break;
				}
				st.pop();
			} 
		}
		cout<<(flag?"yes":"no")<<endl;
	}
}