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>
#include <string>

using namespace std;
int main(){
  string hoge;
  stack<char> foo;

  while(1){

    while(!(foo.empty()))foo.pop();

    getline(cin,hoge);
    if(hoge == ".")break;
    int p = 0;
    for(int i = 0 ; i < (int)hoge.size(); i++ ){
      if(hoge[i] == '[' ||hoge[i] == '(' ||hoge[i] == ')' ||hoge[i] == ']' ){
	hoge[p]+=hoge[i];
      }
    }

    for(int i = 0 ; i < (int)hoge.size() ; i++ ){
      if(hoge[i] == '['||hoge[i] == '('){
	foo.push(hoge[i]);
      }else if(hoge[i] == ']' && !(foo.empty()) && foo.top() == '['){
	foo.pop();
      }else if(hoge[i] == ')' && !(foo.empty()) && foo.top() == '('){
	foo.pop();
      }else goto bad;
    }
    if(foo.empty()){cout << "yes" << endl;continue;}
  bad: cout << "no" << endl; 
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>

using namespace std;

char S[101];

bool solve() {
    stack<char> ps;
    for (int i = 0; S[i]; i++) {
        switch (S[i]) {
            case '(':
                ps.push('(');
                break;
            case '[':
                ps.push('[');
                break;
            case ')':
                if (ps.empty() || ps.top() != '(') {
                    return false;
                }
                ps.pop();
                break;
            case ']':
                if (ps.empty() || ps.top() != '[') {
                    return false;
                }
                ps.pop();
                break;
        }
    }
    return ps.empty();
}

int main() {
    for (;;) {
        gets(S);
        if (strcmp(S, ".") == 0) { break; }
        printf("%s\n", solve() ? "yes" : "no");
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
  string s;
  int i,f;
  while(getline(cin,s),s[0]!='.'){
    stack<char> st;
    for(f=i=0;i<s.size();i++){
      if(s[i]=='('||s[i]=='['){
	st.push(s[i]);
      }else if(s[i]==')'||s[i]==']'){
	if(st.size()&&(st.top()+1==s[i]||st.top()+2==s[i]))st.pop();
	else f=1;
      }
    }
    puts(f&&st.size()?"no":"yes");
  }
}