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

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

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

using namespace std;

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

C++: #include <iostream>
#include <stack>
#include <vector>
uging namespace std;
int main()
{
	string str;
	while( getline(cin,str) && str != '.' ){
		string z;
		for(int i=0;i<str.size();i++)
			if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']')
				z+=str[i];
		stack<char> s;
		bool f = true;
		for(int  i=0;i < z.length();i++){
			if( z.empty() || z[i] == '(' || z[i] == '[' ){
				s.push();
			}else if( (s.top() == '(' && z[i] == ')') || (s.top() == '[' && z[i] == ']') )
				s.pop();
			else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ? "yes": "no")  << endl;
	}

	return 0;
}

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

int main(){

	while(1){
        stack<char> s;
		int p=0, q=0, cont=0;
		string input;

		getline(cin, input);

		if(input[0] == '.' && input[1] == '\0') break;

		for(int i=0;i < input.length() ;i++){
			if(input[i] == '.') break;
			switch(input[i]){
				case '[': s.push(input[i]);
				break;
				case '(': s.push(input[i]);
				break;
				case ']':
                          if(s.empty()){ cont = -1; break;}
                          if(s.top() != '[') cont = -1;
                          s.pop();
				break;
				case ')': q--;
                          if(s.empty()){ cont = -1; break;}
                          if(s.top() != '(') cont = -1;
                          s.pop();
				break;
			}
		}
		if(cont == -1) cout << "no" << endl;
		else cout << "yes" << endl;

	}
	return 0;
}

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

using namespace std;
const static int STRLEN_MAX = 110;

bool analyse( string str ) {
  int i;
  int length = str.size();
  for( i = 0; i < length; i++ ) {
    if( str[ i ] == '(' ) {
      int j;
      for( j = length - 1; j > i; j-- ) {
        if( str[ j ] == ')' ) {
          int len = j - i - 1;
          return analyse( str.substr( i + 1, len ) );
        }
      }
      if( j == i ) { return false; }
    } else if( str[ i ] == '[' ) {
      int j;
      for( j = length - 1; j > i; j-- ) {
        if( str[ j ] == ']' ) {
          int len = j - i - 1;
          return analyse( str.substr( i + 1, len ) );
        }
      }
      if( j == i ) { return false; }
    }
  }
  if( i == length ) { return true; }
}


int main() {
  char str[ STRLEN_MAX ];
  int pos = 0;
  while( 1 ) {
    int c = getchar();
    if( c == '\n' || c == '\r' ) { continue; }
    str[ pos++ ] = c;
    if( c == '.' ) {
      str[ pos ] = '\0';
      if( string( str ) == "." ) { return EXIT_SUCCESS; }
      cout << ( analyse( str ) ? "yes" : "no" ) << endl;
      pos = 0;
    }
  }
}

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

int main(){
	int mc,kc,j=1;
	string s;
	while(1){
		mc=kc=0;
		cin>>s;
		if(s==".") break;
		if(s=="(") mc++;
		if(s=="[") kc++;
		while(1){
			cin>>s;
			if(s==".") break;
			if(s==")"&&mc==0) j=0;
			else if(s==")") mc--;
			if(s=="]"&&kc==0) j=0;
			else if(s=="]") kc--;
			if(s=="(") mc++;
			if(s=="[") kc++;
		}
		if(j==1&&mc==0&&kc==0) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;

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

    stack<char> c;
    bool flag = true;
    rep(i,0,text.size()){
      if(text[i] == '(') c.push('(');
      if(text[i] == '[') c.push('[');
      if(text[i] == ')'){
        if(c.empty()){
          flag = false;
          break;
        }
        if(c.top() == '(') c.pop();
        else{
          flag = false;
          break;
        }       
      }

      if(text[i] == ']'){
        if(c.empty()){
          flag = false;
          break;
        }
        if(c.top() == '[') c.pop();
        else{
          flag = false;
          break;
        }
      }
    }
  
    if(flag) print("yes");
    else print("no");
  }
  
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int tail,c1,c2;
	char str[101];
	int f[101]={0};
	char *s;
	while(1){
		tail=1;
		fgets(str,101,stdin);
		if(str[0]=='.') break;
		s=str;
 		c1=0; c2=0;
		for(;!(*s == '.');s++){
			if(*s=='(') f[tail++]=1;
			if(*s=='[') f[tail++]=2;
			if(*s==')') if(!(f[--tail]==1)) break;
			if(*s==']') if(!(f[--tail]==2)) break;
		}
		if(tail==1 && *s == '.') cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}