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<string>
#include<stack>
using namespace std;
int main(){
  string a;
  while(getline(cin,a)){
    if(a[0]=='.')break;
    stack<char> b;
    int c=0;
    for(int i=0;i<a.size();i++){
      if(a[i]=='['||a[i]=='(')b.push(a[i]);
      if(a[i]==']'||a[i]==')'){
        if(b.empty())c++;
        else if((b.top()=='['&&a[i]==']')||(b.top()=='('&&a[i]==')'))b.pop();
        else c++;
      }
    }
    if(c==0&&b.empty())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

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

int check( string str ){
  stack <char> ch;
  int i;
  int len = str.size();
  for( i = 0; i < len; i++ ){
    if( !(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']' ))continue;
    if( str[i] == '(' || str[i] == '[') ch.push(str[i]);
    else {
     
      if( ch.empty() ){
	  return 0;
	}
    
      if( ch.top() != '(' && str[i] == ')' ) return 0;
      else if( ch.top() == '(' && str[i] == ')' ) ch.pop();
      else if( ch.top() != '[' && str[i] == ']' ) return 0;
      else if( ch.top() == '[' && str[i] == ']' ) ch.pop();

    }
  }
    
  if( !( ch.empty() ) ) return 0;
  return 1;
}

int main(){
 
  string str;
  while( getline(cin,str) ){
    if( str == "." ) break;
    if( check(str) == 1 ) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#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 pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	 // hoge[i] = getchar();
	 	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else break;
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else break;
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        string S;
        getline(cin, S);
        if(S == ".") break;
        //cerr << S << endl;
        stack<int> sta;
        bool clear = true;
        for(int i = 0; i < S.size(); i++) {
            if(S[i] == '(') sta.push(0);
            if(S[i] == '[') sta.push(1);
            if(S[i] == ')') {
                //cerr << "a" << endl;
                if(sta.empty() || sta.top() != 0) clear = false;
                else sta.pop();
            }
            if(S[i] == ']') {
                //cerr << "b" << endl;
                //cerr << sta.top() << endl;
                if(sta.empty() || sta.top() != 1) clear = false;
                else sta.pop();
            }
        }
        if(!sta.empty()) clear = false;
        if(clear) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  string target;
  while(getline(cin, target) and target != "."){
    stack<char> st;
    bool consistent = true;
    REP(i, target.size()){
      if(target[i] == '(') st.push('(');
      if(target[i] == ')') { if(!st.empty() and st.top() == '(') st.pop(); else consistent = false; }
      if(target[i] == '[') st.push('[');
      if(target[i] == ']') { if(!st.empty() and st.top() == '[') st.pop(); else consistent = false; }
      if(!consistent) break;
    }
    if(!st.empty()) consistent = false;
    cout << (consistent ? "yes" : "no") << endl;
  }
  return 0;
}

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

int main(){

  string str;

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

    stack<char> s;
    bool f=true;

    for(int i=0;i<str.size();i++){
      if(str[i]=='('||str[i]=='[') s.push(str[i]);
      if(str[i]==')'){
        if(s.empty()){
          f=false;
          break;
        }
        if(s.top()=='(') s.pop();
        else{
          f=false;
          break;
        }
      }else if(str[i]==']'){
        if(s.empty()){
          f=false;
          break;
        }
        if(s.top()=='[') s.pop();
        else{
          f=false;
          break;
        }
      }
    }
    if(f) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

  return 0;
}

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

int main(void){
    int t;
    int n,m,p;
    int ans;
    string s;
    string str;
    string c;
    vector<int>x;
    while(true) {
        s="";
        while(true){
            getline(cin,str);
            s+=str;
            if(str.back()!='.')s.push_back(' ');
            else break;
        }
        if(s.front()=='.')break;
        t=0;n=0;m=0;p=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='('){t++;c.push_back(s[i]);}
            if(s[i]==')'){
                n++;
                if(c.back()=='['){cout<<"no"<<endl;goto invail;}
                else if(c.size()>0)c.pop_back();
            }
            if(s[i]=='['){m++;c.push_back(s[i]);}
            if(s[i]==']'){
                p++;
                if(c.back()=='('){cout<<"no"<<endl;goto invail;}
                else if(c.size()>0)c.pop_back();
            }
            if(t<n){cout<<"no"<<endl;goto invail;}
            if(m<p){cout<<"no"<<endl;goto invail;}
        }
        if(t>n||m>p)cout<<"no"<<endl;
        else cout<<"yes"<<endl;
        invail:;
    }
    return 0;
}