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>
#ifdef DEBUG
#include <cassert>
#define debug(a) a
#else
#define debug(a)
#endif
using namespace std;
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define foreach(typ, it, cont) for (typ::iterator it = cont.begin(); it != cont.end(); ++it)

short kind(char c) {
    if (c == '(' or c == ')') return 1;
    if (c == '[' or c == ']') return 2;
    debug(assert(false));
}

bool is_balanced(string & s) {
    stack<short> stk;
    foreach (string, it, s) {
        if (*it == '(' or *it == '[') stk.push(kind(*it));
        if (*it == ']' or *it == ')') {
            if (stk.empty() or stk.top() != kind(*it)) return false;
            stk.pop();
        }
    }
    return stk.empty();
}

int main() {
    while (true) {
        string s; getline(cin,s);
        if (s == ".") break;
        cout << (is_balanced(s) ? "yes" : "no") << endl;
    }
    return 0;
}

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

bool is_section_balanced(char stchar){
  char ch,wchar;
  if(stchar=='(')wchar=')';
  else if(stchar=='[')wchar=']';
  while(true){
    cin>>ch;
    if(ch==wchar)return true;
    else if(ch=='(' || ch=='['){if(!is_section_balanced(ch)) return false;}
    else if(ch=='.')return false;
  }
}

int main(){
  char ch,out;
  bool flg=false,flg2,flg3;
  cin >>ch; 
  while(!flg){
    if(ch=='.')flg=true;
    else{
      flg2=false;
      while(!flg2){
	flg3=false;
	if(ch=='('||ch=='['){
	  if(!is_section_balanced(ch)) {cout <<"no\n";flg3=true;}
	}
	else if(ch=='.'){
	  if(!flg3)cout << "yes\n";
	  flg2=true;
	}
	cin>>ch;
      }
    }
  }

}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	cin.tie(0); //対話型には使えない
	ios::sync_with_stdio(false); //printfと共には使えない
	string str;
	while (str = "", getline(cin, str), str != ".") {
		stack<char> s;
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '[' || str[i] == '(') {
				s.push(str[i]);
			} else if(str[i] == ']') {
				if (s.size() == 0) {
					PRINT("no");
					break;
				}
				char t = s.top();
				s.pop();
				if (t != '[') {
					PRINT("no");
					break;
				}
			} else if(str[i] == ')') {
				if (s.size() == 0) {
					PRINT("no");
					break;
				}
				char t = s.top();
				s.pop();
				if (t != '(') {
					PRINT("no");
					break;
				}
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

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

int main(){
  int a;
  char c;
  bool f;
  stack<int> p;

  while(1){
    c = getchar();
    if(c == '.')break;
    f = true;
    while(!p.empty())p.pop();

    do{
      if(c == '(')p.push(1);
      if(c == '[')p.push(2);
      if(c == ')'){
	if(p.empty()){
	  f = false;
	}else{
	  a = p.top();
	  p.pop();
	  if(a!=1)f = false;
	}
      }
      if(c == ']'){
	if(p.empty()){
	  f = false;
	}else{
	  a = p.top();
	  p.pop();
	  if(a!=2)f = false;
	}
      }
      c = getchar(); 
    }while(c != '.');

    if(f && p.empty())cout << "yes" << endl;
    else cout << "no" << endl;

    getchar();
  }

}

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

int main(){
	string s;
	while(getline(cin, s), s != ".") {
    stack<char> st;
    st.push('$');
    bool valid = true;
    for (int i = 0; i < s.size() && valid; i++) {
      if (s[i] == '(' || s[i] == '[') {
        st.push(s[i]);
      } else if (s[i] == ')') {
        valid = st.top() == '(';
        st.pop();
      } else if (s[i] == ']') {
        valid = st.top() == '[';
        st.pop();
      }
    }
    valid = valid && st.top() == '$';
    
    cout << (valid ? "yes" : "no") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int main(){
  string str;
  string tmp;
  while(getline(cin, str) && str != "."){
    int p = 0, q = 0;
    bool flag = 1;
    tmp = "";
    
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '[' || str[i] == '(' || str[i] == ']' || str[i] == ')'){
	tmp += str[i];
      }
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' && tmp[i+1] == ']') flag = 0;
      if(tmp[i] == '[' && tmp[i+1] == ')') flag = 0;
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      //printf("p = %d, q = %d\n", p, q);
      if(p < 0 || q < 0){
	flag = 0;
	break;
      }
      if(tmp[i] == '(') p++;
      if(tmp[i] == '[') q++;
      if(tmp[i] == ')') p--;
      if(tmp[i] == ']') q--;
    }
    if(p != 0 || q != 0) flag = 0;

    
    stack<char> st;
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' || tmp[i] == '[') st.push(tmp[i]);
      else if(tmp[i] == ')'){
	if(st.empty() || st.top() != '('){ flag = 0; break;}
	else st.pop();
      }
      else if(tmp[i] == ']'){
	if(st.empty() || st.top() != '['){ flag = 0; break;}
	else st.pop();
      }
    }
    
    //cout << tmp << endl;
    //printf("p = %d, q = %d\n", p, q);*/
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;    
  }
  return 0;
}

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	bool flag;
	while(1){
		flag = false;
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(1){
			if(letter[i] == '.') break;
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			}
			i++;
		}
		if(flag == false)
		cout << "yes" << endl;
		while(st.empty() == true)
			st.pop();
	}
	return 0;
}