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

using namespace std;

int main(){
  string s;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]==')' || s[i]=='(' || s[i]=='[' || s[i]==']')ch+=s[i];

    stack<char> str;
    bool flag = true;
    for(int i=0;i<ch.length();i++){
      
      if(str.empty() || ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      else if((ch[i]==')' && str.top()=='(')||(ch[i]==']' && str.top()=='[')){str.pop();}
      else {
	flag = false;
	break;
      }
    }

    cout << (flag && str.empty()?"YES":"NO") << endl;

  }

}

C++: #include <stdio.h>
int main(){
  int i,ib;
  char a,s[100];
  while(1){
    i=0;
    scanf("%c",&a);
    if(a=='.')break;
    else if(a=='('){
      s[i]='(';
      i++;
    }else if(a==')'){
      s[i]=')';
      i++;
    }else if(a=='['){
      s[i]='[';
      i++;
    }else if(a==']'){
      s[i]=']';
      i++;
    }
    while(1){
      scanf("%c",&a);
      if(a=='.'){
	if(i==0){
	  printf("Yes\n");
	  break;
	}else {
	  printf("No\n");
	  break;
	}
      }else if(a=='('){
	s[i]='(';
	i++;
      }else if(a==')'){
	if(s[i-1]=='(')i--;
	else {
	  s[i]=')';
	  i++;
	}
      }else if(a=='['){
	s[i]='[';
	i++;
      }else if(a==']'){
	if(s[i-1]=='[')i--;
	else {
	  s[i]=']';
	  i++;
	}
      }
    }
    scanf("%c",&a);
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long L;
string st;
int main()
{
    while(1){
        getline(cin,st);
        if(st[0]=='.')return 0;
        stack<char>s;
        L l=st.length();
        for(L i=0;i<l;i++){
            if(st[i]=='(' || st[i]=='['){
                s.push(st[i]);
            }
            else if(st[i]==']' || st[i]==')' ){
                if(!s.empty()){
                    if(st[i]==']'){
                        if(s.top()!='['){
                            break;
                        }
                        else s.pop();
                    }
                    else if(st[i]==')'){
                        if(s.top()!='('){
                            break;
                        }
                        else s.pop();
                    }
                }
                else{
                    s.push(')');break;
                }
            }
        }
        if(!s.empty())printf("no\n");
        else printf("yes\n");
    }


    return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
	map<char, int> conv;
	conv['('] = 0;
	conv[')'] = 0;
	conv['['] = 1;
	conv[']'] = 1;

	map<char, int> mode;
	mode['('] = 1;
	mode[')'] = -1;
	mode['['] = 1;
	mode[']'] = -1;

	string str;
	while ( getline(cin, str), str != "." ) {
		vector<int> prev;
		int nest = 0;
		bool ans = true;
		for (int i = 0; i < str.size(); ++i) {
			if (conv.find(str[i]) != conv.end()) {
				int bid = conv[str[i]];
				if (mode[str[i]] < 0) {
					if (nest <= 0 || prev[nest-1] != bid) ans = false;
					--nest;
				}
				else {
					if (++nest > prev.size()) prev.push_back(bid);
					else prev[nest-1] = bid;
				}
				if (!ans) break;
			}
		}
		if (nest != 0) ans = false;
		if (ans) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

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

//A rope may form )( a trail in a maze.

int main(){
	while(1){
		string data;
		for(char in = 0;in != '.';){
			in = cin.get();
			data += in;
		}
		cin.get();
		if(data == ".") break;
		
		stack<char> stk;
		int pc = 0;
		while(1){
			char in = data[pc];
			pc++;
			
			if(in == '(' || in == '['){
				stk.push(in);
			}
			if(in == ')' || in == ']'){
				if(stk.empty()){
					cout << "no" << endl;
					break;
				}
				char begin = stk.top();
				if((begin == '(' && in != ')') || (begin == '[' && in != ']')){
					cout << "no" << endl;
					break;
				}else{
					stk.pop();
				}
			}
			if(in == '.'){
				if(stk.empty()){
					cout << "yes" << endl;
				}else{
					cout << "no" << endl;
				}
				break;
			}
		}
	}
	
	return 0;
}

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

int main(){
   string s;
   while( getline(cin,s) ){ // 文字列に半角スペースを含むので1行読み込みします
       if( s == "." ) break;
       stack<char> st;
       bool flag = true;

       for(int i=0 ; i < s.size() ; i++ ){
           char c = s[i];
           if( c == '(' || c == '[' ){ // 括弧の初めが来たら
               st.push( c );
           }else if( c == ')' ){ // 括弧の終わり')'が来たら
               if( st.empty() || st.top() == '[' ){
                   flag = false;
                   break;
               }else if( st.top() == '(' ){
                   st.pop();
               }
           }else if( c == ']' ){ // 括弧の終わり']'が来たら
               if( st.empty() || st.top() == '(' ){
                   flag = false;
                   break;
               }else if( st.top() == '[' ){
                   st.pop();
               }
           }
       }
       if( flag && st.empty() )
           cout << "yes" << endl;
       else
           cout << "no" << endl;
   }
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	string s;
	while (1){
		stack<char> sc;
		getline(cin, s);
		if (s[0] == '.'&&s.length() == 1)break;
		for (int i = 0; s[i] != '.'; i++){
			if (s[i] == '(' || s[i] == '[') sc.push(s[i]);
			if (s[i] == ')'){
				if (!sc.empty()&&sc.top() == '(')sc.pop();
				else {
					sc.push('!');
					break;
				}
			}
			if (s[i] == ']'){
				if (!sc.empty() && sc.top() == '[')sc.pop();
				else {
					sc.push('!');
					break;
				}
			}
		}
		if (sc.empty())cout << "yes" << endl;
		else cout << "no" << endl;
	}
}