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

using namespace std;

int main(){
	int rk=0, sk=0, len=0;
	char in;
	bool check=false;
	vector<char> st;
	st.push_back(' ');
	while(true){
		scanf("%c", &in);
		if( in == '\n' ) continue;
		if( in == '.' && len == 0 ) break;
		len++;
		if( in == '(' ){ rk++; st.push_back('('); }
		if( in == '[' ){ sk++; st.push_back('['); }
		if( in == ')' ){
			if( --rk < 0 || st.empty() || st.back() != '(' ){
				check=true;
				st.push_back(' ');
			}
			st.pop_back();
		}
		if( in == ']' ){
			if( --sk < 0 || st.empty() || st.back() != '[' ){
				check=true;
				st.push_back(' ');
		}
			st.pop_back();
		}
		if( in == '.' ){
			cout << (check?"no":"yes") << endl;
			rk = 0;
			sk = 0;
			len = 0;
			check = false;
			st.clear();
			st.push_back(' ');
		//	while(st.empty()) st.pop();
		//	st.push(' ');
		}
	}
	return 0;
}

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

using namespace std;       
int main(){
  string s;
  int i=0,j=0,k=0;
  while(cin >> s){
    while(s[i] == '\0'){
      
      if(s[i] == '('){
	j++;  
      }
      if(s[i] == ')'){
	j--;  
      }
      if(s[i] == '['){
	k++;  
      }
      if(s[i] == ']'){
	k--;  
      }   
    }
  }
  if(j == 0 && k == 0){
    cout << "yes" <<endl;
  }else{
    cout<<"no"<<endl;
  }
  return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

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

      int n = s.size();
      stack<char> stk;
      bool ng = false;
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.size() == 0 || stk.top() != '(') {
               ng = true;
               break;
            }
            stk.pop();
         }
         if (s[i] == ']') {
            if (stk.size() == 0 || stk.top() != '[') {
               ng = true;
               break;
            }
            stk.pop();
         }
      }
      if (!ng && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }

   return 0;
}

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

  return 0;
}

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

map<char,char> m;
stack<char> st;	

void check(string str){
	for(int i=0;i<str.size();i++){
		if(
			str[i]=='(' ||
			str[i]=='[' 
		){
			st.push(str[i]);
		} else if(
			str[i]==')' ||
			str[i]==']' 
		){
			if(!st.empty()){
				if(m[st.top()]==str[i]){
					st.pop();
				}
			}
		}
	}
}

bool isPeriod(string str){
	for(int i=0;i<str.size();i++){
		if(str[i]=='.') return true;
	}
	return false;
}

int main(){
	m['(']=')';
	m['[']=']';
	string str;
	while(getline(cin,str)){
		if(!str.compare(".")) break;
		check(str);
		if(isPeriod(str)){
			if(st.empty()){
				cout << "yes" << endl;
			}else {
				cout << "no" << endl;
			}
			while(!st.empty()){
				st.pop();
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
	string in;
	while(getline(cin, in), in!=".") {
		string stk = "";
		bool ok = true;
		rep(i, in.length()) {
			if( in[i] == '(' ) {
				stk += ')';
			} else if( in[i] == '[' ) {
				stk += ']';
			}
			else if( in[i] == ')' || in[i] == ']' ) {
				if( stk.length()>0 && stk[stk.length()-1] == in[i] ) {
					stk = stk.substr(0, stk.length()-1);
				} else {
					ok = false;
					break;
				}
			}
		}
		if(ok) {
			cout << (stk.length() == 0 ? "yes" : "no") << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

int main () {
    string str;
    map<char,char> c;
    c[']'] = '[';
    c[')'] = '(';
    while (getline(cin,str), str != ".") {
        stack<char> s;
        bool flag = true;
        for (int i = 0; flag && i < str.size(); i++) {
            if (string("[()]").find(str[i]) == string::npos) continue;
            if (string("[(").find(str[i]) != string::npos) {
                s.push(str[i]);
            }
            else if (string("])").find(str[i] != string::npos)) {
                if (s.size() == 0) flag = false;
                else if (c.find(str[i]) != c.end() && c[str[i]] == s.top()) s.pop();
                else if (c.find(str[i]) != c.end() && c[str[i]] == s.top()) s.pop();
                else flag = false;
            }
        }

        cout << (flag && !s.size() ? "yes" : "no") << endl;
    }
}