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<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<stack>

using namespace std;

#define INF 999999999

int main(){
	int i, j;
	char s[101];
	stack<int> st;
	int flag;
	
	while(1){
		fgets(s, sizeof(s), stdin);
		if(s[0]=='.')break;
		flag = 1;
		while(!st.empty()) st.pop();
		
		for(i=0;s[i]!='\0';i++){
			if(s[i]=='(') st.push(1);
			else if(s[i]=='[') st.push(2);
			else if(s[i]==')'){
				if(st.empty()||st.top()==2){
					flag = 0;
					break;
				}
				else{
					st.pop();
				}
			}
			else if(s[i]==']'){
				if(st.empty()||st.top()==1){
					flag = 0;
					break;
				}
				else{
					st.pop();
				}
			}
		}
		
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

bool check(string s) {
    stack<char> stk;
    stk.push('#');
    for (auto c : s) {
        if (c == '(' || c == '[') {
            stk.push(c);
        } else if (c == ')' || c == ']') {
            if ((stk.top() == '(' && c == ')') || (stk.top() == '[' && c == ']')) {
                stk.pop();
            } else {
                return false;
            }
        }
    }
    return stk.size() == 1;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string s;
    while (getline(cin, s), s[0] != '.') {
        cout << (check(s) ? "yes" : "no") << endl;
    }
}

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

using namespace std;

string hoge;
string hogehoge;
stack<char> foo;

int main(void){

  while(1){

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

    getline( cin , hoge );
    if( hoge[0] == '.' )break;

    hogehoge = "";
    for( int i = 0 ; i < hoge.size() ; i++ ){
      if( hoge[i] == '[' || hoge[i] == ']' || hoge[i] == '(' || hoge[i] == ')' ){
	hogehoge += hoge[i]; 
      }
    }

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

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

int main(){
  
  string str;

  while(1){

    getline(cin, str);
    if(str[0] == '.') break;

    vector<int> v;

    for(int i = 0; i < (int)str.size(); i++){
      if(str[i] == '('){
	v.push_back(0);
      }else if(str[i] == ')'){
	v.push_back(1);
      }else if(str[i] == '['){
	v.push_back(2);
      }else if(str[i] == ']'){
	v.push_back(3);
      }
    }

    int cnt = 0, judge = 0, o[2] = {}, p[2] = {};

    for(int i = 0; i < (int)v.size(); i++){
      if(v[i] == 0){
	for(int j = i+1; j < (int)v.size(); j++){
	  if(v[j] == 1){
	    for(int l = i+1; l < j; l++){
	      if(v[l] == 0) o[0]++;
	      if(v[l] == 1) o[1]++;
	      if(v[l] == 2) p[0]++;
	      if(v[l] == 3) p[1]++;
	      //   cout << o[0] << o[1] << p[0] << p[1] << endl;
	    }
	    
	    if(o[0] == o[1] && p[0] == p[1]){
	      v[i] = 7;
	      v[j] = 7; 
	    }
	      o[0] = o[1] = p[0] = p[1] = 0;

	  }
	}
      }else if(v[i] == 2){
	for(int j = i+1; j < (int)v.size(); j++){
	  if(v[j] == 3){
	    for(int l = i+1; l < j; l++){
	      if(v[l] == 0) o[0]++;
	      if(v[l] == 1) o[1]++;
	      if(v[l] == 2) p[0]++;
	      if(v[l] == 3) p[1]++;
	      //   cout << o[0] << o[1] << p[0] << p[1] <<  v[0] <<endl;
	    }
	    
	  
	    if(o[0] == o[1] && p[0] == p[1]){
	      v[i] = 7;
	      v[j] = 7;
	    }
	    o[0] = o[1] = p[0] = p[1] = 0;
  	  }
	}
      }
      /*   for(int k = 0; k < (int)v.size(); k++){
	   cout << v[k];
	   }
	   cout << endl;
      */
    }
     
    
    for(int i = 0; i < (int)v.size(); i++){
      if(v[i] == 7){
    	cnt++; 
      }
    }

    if(cnt == (int)v.size()){
      cout << "yes" << endl;
      cnt = 0;
    }else if(cnt != (int)v.size()) cout << "no" << endl;
    // cout << cnt << " " << (int)v.size() << endl;
  }
  
  return 0;
}

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

using namespace std;

int main(){

   while(1){
      string s;
      getline(cin, s);
      if(s==".") break;
      
      stack<char> S;
      for(int i=0; i<s.size(); i++){
         if(s[i]=='(' or s[i]=='['){
            S.push(s[i]);
         }else if(s[i]==')'){
            if(S.empty()){
               cout<< "no"<< endl;
               break;
            }
            char c=S.top();
            if(c=='('){
               S.pop();
            }else{
               cout<< "no"<< endl;
               break;
            }
         }else if(s[i]==']'){
            if(S.empty()){
               cout<< "no"<< endl;
               break;
            }
            char c=S.top();
            if(c=='['){
               S.pop();
            }else{
               cout<< "no"<< endl;
               break;
            }
         }else if(s[i]=='.'){
            if(S.empty()){
               cout<< "yes"<< endl;
            }else{
               cout<< "no"<< endl;
            }
         }
      }
   }
   return 0;
}