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;

char bl[5]= "([)]";

int main(){
    string str;
    while(getline(cin,str) && str[0]!='.'){
        stack<char> stk;
        for(int i=0; str[i]!='.'; i++){
            for(int j=0; j<2; j++){
                if(str[i]==bl[j]){
                    stk.push(str[i]);
                }
            }
            for(int j=2; j<4; j++){
                if(str[i]==bl[j]){
                    if(stk.empty() || stk.top()!=bl[j-2]){
                        stk.push(0);
                        break;
                    }else{
                        stk.pop();
                    }
                }
            }
        }
        
        if(stk.empty()){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}

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

#define pb         push_back

const int INF = 100000000;

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

		stack<char> st;
		bool success = true;
		for(int i=0; i<s.size(); i++){
			if(s[i] == '(' || s[i] == '['){
				st.push(s[i]);
			}
			if(s[i] == ')'){
				if(st.size() == 0){
					success = false;
					break;
				}
				
				char c = st.top();
				st.pop();
				if(c != '(') success = false;
			}
			if(s[i] == ']'){
				if(st.size() == 0){
					success = false;
					break;
				}

				char c = st.top();
				st.pop();
				if(c != '[') success = false;
			}
		}

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

	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        stack<char> w;
        int d=0;
        for(int i=0;i<s.size();i++){
            if(s[i]=='['||s[i]=='(')w.push(s[i]);
            else if(s[i]==']'){
                if(w.top()=='[')w.pop();
                else d++;
            }
            else if(s[i]==')'){
                if(w.top()=='(')w.pop();
                else d++;
            }
            if(d)break;
        }
        if(w.empty())cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}

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

using namespace std;

int main(void)
{
	char c;

	while(1){
		cin.get(c);
		if(c=='.') break;
			
		stack<char> s;
		if(c=='(' || c=='[') s.push(c);
		else if(c==')' || c==']') s.push(c);

		while(1){
			cin.get(c);
			if(c=='.') {
				cin.get(c);
				if(c=='\n') break;
			}

			if(c=='(' || c=='[') s.push(c);
				
			else if(c==')'){
				if(!s.empty() && s.top()=='(') s.pop();
				else s.push(c);
			}
			else if(c==']'){
				if(!s.empty() && s.top()=='[') s.pop();
				else s.push(c);
			}
		}

		if(s.empty()) cout << "yes" << endl;
		else cout << "no" << endl;

	}

	return 0;
}

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

bool backet(char a){
  if(a=='(')return true;
  if(a==')')return true;
  if(a=='[')return true;
  if(a==']')return true;
  if(a=='{')return true;
  if(a=='}')return true;
  return false;
}

bool check(char a,char b){
  if(a=='(' && b==')')return true;
  if(a=='[' && b==']')return true;
  if(a=='{' && b=='}')return true;
  return false;
}

int main(){
  string s;
  int ans = 0;
  //int n;

  //cin >> n;
  //for(int i=0;i<n;i++){
  while(getline(cin, s)){

    for(int j=0;j<(int)s.size();j++)
      if(!backet(s[j])){
	s.erase(s.begin()+j);
	j--;
      }

    bool f = true;
    while(f){
      f = false;
      for(int j=0;j<(int)s.size()-1;j++)
	if(check(s[j],s[j+1])){
	  s.erase(s.begin()+j);
	  s.erase(s.begin()+j);
	  j--;
	  f = true;
	}
    }
    if(s.size())cout << "no\n";
    else cout << "yes\n";
    //if(s.size()==0)ans++;
  }
  //cout << ans << endl;
}

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

bool issame(char a,char b){
     if(a=='(')return b==')';
     if(a=='[')return b==']';
}

int main(){
     while(1){
	  char in;
	  in=cin.peek();
	  //cout<<in;
	  if(in=='.')return 0;
	  stack<char> sta;
	  bool iscorrect=true;
 
	  while(cin.get(in),in!='.'){
	       if(cin.eof())return 0;
	       if(in=='('||in=='['){
		    sta.push(in);
	       }else if(in==')'||in==']'){
		    if(sta.empty()||!issame(sta.top(),in)){
			 iscorrect=false;
			 break;
		    }
		    sta.pop();
	       }
	  }
	  cout<<((iscorrect&&sta.empty())? "yes":"no")<<endl;
	  cin.ignore(100,'\n');
     }
}

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

int main(void) {
    string s;

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

        stack<char> sc;
        char tmp;
        for (auto i : s) {
            switch (i) {
            case '(':
                sc.push('(');
                break;
            case '[':
                sc.push('[');
                break;
            case ')':
                if (sc.size() == 0) {
                    flag = true;
                    break;
                }

                tmp = sc.top();
                if (tmp == '(') {
                    sc.pop();
                } else {
                    flag = true;
                }
                break;
            case ']':
                if (sc.size() == 0) {
                    flag = true;
                    break;
                }

                tmp = sc.top();
                if (tmp == '[') {
                    sc.pop();
                } else {
                    flag = true;
                }
                break;
            }
            if (flag) break;
        }
        if (flag || sc.size() != 0) {
            cout << "no" << endl;
        } else {
            cout << "yes" << endl;
        }
    }
    return 0;
}

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

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

  while(1){

    while(!(foo.empty()))foo.pop();
    hogehoge = "\0";
    getline(cin,hoge);
    if(hoge == ".")break;

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