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"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (string s; getline(cin, s) && s != ".";) {
		stack<char> st;
		rep(i, 0, s.size()) {
			if (s[i] == '(') {
				st.emplace('(');
			}
			if (s[i] == '[') {
				st.emplace('[');
			}
			if (s[i] == ')') {
				if (st.empty() || st.top() == '[') {
					cout << "no" << endl;
					break;
				}
				st.pop();
			}
			if (s[i] == ']') {
				if (st.empty() || st.top() == '(') {
					cout << "no" << endl;
					break;
				}
				st.pop();
			}
			if (s[i] == '.') {
				if (st.size()) {
					cout << "no" << endl;
					break;
				}
				cout << "yes" << endl;
			}
		}
	}
	return 0;
}

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

int main()
{
	string str;
	while (getline(cin, str), str != "."){
		int c = 0, s = 0, f = 0;
		bool res = false;
		for (int p = 0; p < str.size(); p++){
			if (str[p] == '('){
				f = 1;
				c++;
			}
			else if (str[p] == ')'){
				if (f == 2) break;
				f = 0;
				c--;
			}
			else if (str[p] == '['){
				f = 2;
				s++;
			}
			else if (str[p] == ']'){
				if (f == 1) break;
				f = 0;
				s--;
			}
			if (c < 0 || s < 0) break;
			if (p == str.size() - 1) res = true;
		}
		if (res && !c && !s) puts("yes");
		else puts("no");
	}
	
	return 0;
}

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


#define INPUT_MAX 101	// 入力文字数の最大値
#define KAKKO_MAX 49	// 左括弧の数の最大値

using namespace std;

int main(void)
{
	int countMaru = 0;			// '('の数 - ')'の数
	int countKaku = 0;			// '['の数 - ']'の数
	int idx = 0;				// stackに入っている値の数
	string stack(KAKKO_MAX, '\0');		// '('、'['を入力順に格納する変数
	string dataset(INPUT_MAX, '\0');	// 各データセットを格納する変数
	
	while(getline( cin, dataset))
	{
		if(dataset[0] == '.')
		{
			break;
		}
		for(int i = 0; i < INPUT_MAX; i++)
		{
			if(dataset[i] == '.')
			{
				if((countMaru == 0) && (countKaku == 0))
				{
					cout << "yes\n";
					break;
				}
				else
				{
					cout << "no\n";
					break;
				}
			}
			else if(dataset[i] == '(')
			{
				if(idx == KAKKO_MAX)
				{
					cout << "no\n";
					break;
				}
				countMaru++;
				stack[idx] = '(';
				idx++;
			}
			else if(dataset[i] == '[')
			{
				if(idx == KAKKO_MAX)
				{
					cout << "no\n";
					break;
				}
				countKaku++;
				stack[idx] = '[';
				idx++;
			}
			else if(dataset[i] == ')')
			{
				if(idx == 0)
				{
					cout << "no\n";
					break;
				}
				else if(stack[idx-1] == '[')
				{
					cout << "no\n";
					break;
				}
				else
				{
					idx--;
					stack[idx] = '\0';
					countMaru--;
				}
			}
			else if(dataset[i] == ']')
			{
				if(idx == 0)
				{
					cout << "no\n";
					break;
				}
				else if(stack[idx-1] == '(')
				{
					cout << "no\n";
					break;
				}
				else
				{
					idx--;
					stack[idx] = '\0';
					countKaku--;
				}
			}
			else
			{
				// 処理なし
			}
		}
		
		idx = 0;
		countMaru = 0;
		countKaku = 0;
	}
	
	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;
	    }
	    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]++;
	    }
	    
	  }
	  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 <bits/stdc++.h>
using namespace std;

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

      int n = s.size();
      stack<char> stk;
      bool ok = 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() != '(') {
               ok = true;
               break;
            }
            // )と対応する
            stk.pop();
         }
         if (s[i] == ']') {
            // ]と対応しない
            if (stk.size() == 0 || stk.top() != '[') {
               ok = true;
               break;
            }
            // [と対応する
            stk.pop();
         }
      }
      if (!ok && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }

   return 0;
}

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