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>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    string inp;
    while(getline(cin, inp)){
        if(inp.size() == 1 && inp[0] == '.') break;
        string str;
        rep(i,inp.size()){
            if(inp[i] == '(' || inp[i] == ')' || inp[i] == '[' || inp[i] == ']'){
                str+=inp[i];
            }
        }
        while(str.size()){
            string copy = str;
            rep(i,str.size() - 1){
                if((str[i] == '(' && str[i + 1] == ')') || (str[i] == '[' && str[i + 1] == ']')){ 
                    str.erase(i,2);
                    break;
                }
            }
            if(copy == str) break;
        }
        if(str.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <stdio.h>
#include <string.h>

#define MAX (1000)

int main(void)
{
	int sp;
	char stack[MAX];
	char str[MAX + 1];
	while (1){
		int i;

		fgets(str, MAX * 2, stdin);
		if (str[0] == '.'){
			break;
		}

		sp = 0;
		for (i = 0; str[i] != '\n'; i++){
			if (str[i] == '[' || str[i] == '('){
				stack[sp++] = str[i];
			}
			else if (str[i] == ')' || str[i] == ']'){
				if (sp == 0){
					break;
				}
				char top = stack[--sp];
				if (top == '['){
					top = ']';
				}
				else {
					top = ')';
				}
				if (top != str[i]){
					break;
				}
			}
		}
	
		
		if (str[i] == '\n' && str[i - 1] == '.'){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

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

char stk[128];
int sp;

void push(char c){
  stk[sp++] = c;
}
int pop(){
  if (sp==0) return -1;
  return stk[--sp];
}

int main(void){
  string buf;
  int flg, t;
  
  while (true){
    getline(cin, buf);
    if (buf==".") break;
    sp = 0;
    flg = 1;
    for (int i=0; i<buf.size(); i++){
      if (buf[i]=='(' || buf[i]=='['){
        push(buf[i]);
      } else if (buf[i]==')' || buf[i]==']'){
        t = pop();
        if ((buf[i]==')' && t!='(') || (buf[i]==']' && t!='[')){
          flg = 0;
          break;
        }
      }
    }
    if (sp) flg = 0;
    cout << (flg?"yes":"no") << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	stack<char> s;

	while (true){
		char str[128];
		fgets(str, sizeof(str), stdin);

		if (str[0] == '.'){
			break;
		}

		while (!s.empty()){
			s.pop();
		}

		bool flag = true;
		for (int i = 0; str[i] != '.'; i++){
			if (str[i] == '(' || str[i] == '['){
				s.push(str[i]);
			}

			if (str[i] == ')'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '('){
					s.pop();
				}
				else if (s.top() == '['){
					flag = false;
					break;
				}
			}
			if (str[i] == ']'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '['){
					s.pop();
				}
				else if (s.top() == '('){
					flag = false;
					break;
				}
			}
		}

		if (flag && s.empty()){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  char s[101];
  while(fgets(s,sizeof(s),stdin),s[0]!='.'){
    stack<char> a;
    int i=0;
    for(;s[i]!='.';++i){
      if(!(s[i]-'(')||!(s[i]-'['))a.push(s[i]);
      if(s[i]==')')if(a.empty()||a.top()!='(')break;else a.pop();
      if(s[i]==']')if(a.empty()||a.top()!='[')break;else a.pop();
    }cout<<(s[i]!='.'||!a.empty()?"no":"yes")<<endl;
  }
}

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

void solve(string s){
    stack<char> stk;
    for(char c:s){
        if(c=='('){
            stk.push('(');
        }
        if(c=='['){
            stk.push('[');
        }
        if(c==')'){
            if(!stk.empty()&&stk.top()=='(')stk.pop();
            else {cout<<"no"<<endl;return;}
        }
        if(c==']'){
            if(!stk.empty()&&stk.top()=='[')stk.pop();
            else {cout<<"no"<<endl;return;}
        }
    }
    cout<<"yes"<<endl;
}

int main (){
    string s;
    while(getline(cin,s),s[0]!='.'&&s.size()!=1){
        solve(s);
    }
}

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

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i-1]=='.') break;
        }
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }else if(st.empty()){
                if(str[i]==')' || str[i]==']') judge = false;
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

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

typedef stack<char> P;

int main()
{
     const char s[5] = "()[]";
     string str;
     while (getline(cin, str), str.size() > 1) {
          P p;
          bool flag  =true;
          for (int i = 0; i < str.size(); i++) {
               if (str[i] == s[0] || str[i] == s[2]) p.push(str[i]);
               else if (str[i] == s[1] || str[i] == s[3]) {
                    if (p.size() < 1) {
                         flag = false;
                         break;
                    } else if (str[i] == s[1] && p.top() == s[0]) p.pop();
                    else if (str[i] == s[3] && p.top() == s[2]) p.pop();
                    else {
                         flag = false;
                         break;
                    }
               }
          }
          if (flag && p.size() == 0) cout << "yes" << endl;
          else cout << "no" << endl;
     }

     return 0;
}