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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int main() {
  string line;
  while (getline(cin, line)) {
    if (line == ".") break;
    stack<char> s;
    const int N = line.size();
    bool ok = true;
    
    rep(i,N) {
      if ((line[i] == '[') || (line[i] == '(')) {
        s.push(line[i]);
      } else if (line[i] == ']') {
        if (s.size() && s.top() == '[') {
          s.pop();
        } else {
          ok = false; break;
        }
      } else if (line[i] == ')') {
        if (s.size() && s.top() == '(') {
          s.pop();
        } else {
          ok = false; break;
        }
      }
    }
    printf("%s\n", ok ? "yes" : "no");
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
	for(;;){
		string word;
		stack<int> log;
		getline(cin,word);
		if(word == "."){break;}
		for(int i=0; i<word.size(); i++){
			if(word[i] == '('){log.push(1);}
			if(word[i] == '['){log.push(2);}
			if(word[i] == ')'){
				if(log.empty()){cout<<"no"<<endl;goto jump;}
				else if(log.top() == 1){log.pop();}
				else if(log.top() != 1){cout<<"no"<<endl;goto jump;}
			}
			if(word[i] == ']'){
				if(log.empty()){cout<<"no"<<endl;goto jump;}
				else if(log.top() == 2){log.pop();}
				else if(log.top() != 2){cout<<"no"<<endl;goto jump;}
			}
		}
		if(log.empty()){cout <<"yes"<<endl;}
		else{cout <<"no"<<endl;}
		jump:;
	}
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp

#include <iostream>
#include <string>
#include <stack>
using namespace std;

// 方針：'('を見たら')'をStに入れる。'['を見たら']'をSに入れる。
// ']'を見たらStがemptyでなくtopが']'であることを確かめてpopする。
// ')'もおなじ。
// おかしくなったらその瞬間にno。だめでなければyes。
// ……ではなく、ダメでなかった場合は、Stが空ならyesである。

string S;

bool ok() {
  stack<char> St;
  for (unsigned int i=0; i<S.size(); i++) {
    switch(S[i]) {
    case '(':
      // cerr << S[i] << " pushed." << endl;
      St.push(')');
      break;
    case '[':
      // cerr << S[i] << " pushed." << endl;
      St.push(']');
      break;
    case ')':
      if (!St.empty() && St.top() == ')') {
	// cerr << S[i] << " popped." << endl;
	St.pop();
	break;
      } else {
	// cerr << "fails." << endl;
	return false;
      }
    case ']':
      if (!St.empty() && St.top() == ']') {
	// cerr << S[i] << " popped." << endl;
	St.pop();
	break;
      } else {
	// cerr << "fails." << endl;
	return false;
      }
    default: break;
    }
  }
  return St.empty();
}

int main() {
  while (getline(cin, S) && S != ".") {
    if (ok()) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;

int main(){
	while (getline(cin, s)){
		if (s == ".")break;
		bool f = 1;
		vector<char> vc;
		vc.clear();
		int a = 0, b = 0;
		REP(i, s.size()){
			if (s[i] == '('){
				a++;
				vc.push_back(s[i]);
			}
			if (s[i] == '['){
				b++;
				vc.push_back(s[i]);
			}
			if (s[i] == ')'){
				a--;
				if (a < 0 || b < 0)f = 0;
				if (!vc.empty()){
					if (vc[vc.size() - 1] == '[')f = 0;
					else vc.pop_back();
				}
			}
			if (s[i] == ']'){
				b--;
				if (a < 0 || b < 0)f = 0;
				if (!vc.empty()){
					if (vc[vc.size() - 1] == '(')f = 0;
					else vc.pop_back();
				}
			}
		}
		if (f)cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

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

int main(){
    char s[108];
    stack<char> stk;
    int no = 0;
    cin.getline(s, 101);
    while(s[0] != '.' && s[1] != '\0'){
        for(int i = 0; i < 101; i++){
            if(s[i] == '(') stk.push('(');
            if(s[i] == '[') stk.push('[');
            if(s[i] == ')'){
                if(stk.empty() || stk.top() != '('){
                    no = 1;
                    break;
                }
                stk.pop();
            }
            if(s[i] == ']'){
                if(stk.empty() || stk.top() != '['){
                    no = 1;
                    break;
                }
                stk.pop();
            }
            if(s[i] == '\0') break;
        }
        if(no == 0){
            printf("yes\n");
        } else {
            printf("no\n");
        }
        while(!stk.empty()){
            stk.pop();
        }
        no = 0;
        cin.getline(s, 101);
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

void judge(string str){
	vector<char> B;
	B.push_back('$');

	for(int i=0;i<str.length();i++){
		if(str[i] == '(')
			B.push_back('(');
		else if(str[i] == '[')
			B.push_back('[');
		else if(str[i] == ')')
			if(B[B.size()-1] == '(')
				B.pop_back();
			else
				B.push_back(')');
		else if(str[i] == ']')
			if(B[B.size()-1] == '[')
				B.pop_back();
			else
				B.push_back(']');
	}

	if(B.size() == 1)
		cout<<"yes"<<endl;
	else
		cout<<"no"<<endl;
}

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

		judge(str);
	}

	return 0;
}

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

int main(){

    string s;


    while (1){
	bool b = true;
	
	getline(cin, s);
	if (s == ".") break;

	stack<char> st;
	
	for (int i = 0; i < s.size(); i++){
	    
	    switch (s[i]){
	    case '(': st.push('('); break;
	    case ')':
		if (st.empty() || st.top() != '(') b = false;
		else st.pop();
		break;
	    case '[': st.push('['); break;
	    case ']':
		if (st.empty() || st.top () != '[') b = false;
		else st.pop();
		break;
	    default: break;
	    }
	}

	if (b) cout << "yes" << endl;
	else cout << "no" << endl;
    }

}