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<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  char c;
  while((c=getchar())!='.'){
    if(c=='.')break;
    int cnthi=0;
    int cnthika=0;
    vector<int>hkf;
    bool ans=true;
    if(c=='('){cnthi++;hkf.pb(1);}
    else if(c=='['){cnthika++;hkf.pb(2);}
    else if(c==')')ans=false;
    else if(c==']')ans=false;
    char c2;
    while((c2=getchar())!='\n'){
      if(c2=='('){cnthi++;hkf.pb(1);}
      else if(c2=='['){cnthika++;hkf.pb(2);}
      else if(c2==')'){cnthi--;if(hkf.empty()){ans=false;}
	else if(hkf[hkf.size()-1]==1){hkf.pop_back();}
	else if(hkf[hkf.size()-1]!=1){ans=false;}}
      else if(c2==']'){cnthika--;if(hkf.empty()){ans=false;}
	else if(hkf[hkf.size()-1]==2){hkf.pop_back();}
	else if(hkf[hkf.size()-1]!=2){ans=false;}
      }
      if(cnthi<0||cnthika<0)
	ans=false;
    }
    if(cnthi!=0||cnthika!=0)
      ans=false;
    if(ans)
      cout<<"yes"<<endl;
    else
      cout<<"no"<<endl;
  }
  return 0;
}

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

stack<char> st;

string::size_type find(char ch) {
  string sch; sch.push_back(ch);
  string tgt = "()[]";
  return tgt.find(sch);
}

int main() {
  string str;
  string s;
  
  while(getline(cin, str)) {
    if(str == ".") break;
    s.clear();
    for(unsigned i=0; i<str.size(); i++) {
      if(find(str[i]) != string::npos) {
	s.push_back(str[i]);
      }
    }
    
    int len = s.size();
    char ch;
    
    bool ok = 1;
    for(int i=0; i<len; i++) {
      if(s[i] == '(') st.push(s[i]);
      if(s[i] == '[') st.push(s[i]);
      
      if(s[i] == ')') {
	if(!i) {
	  ok = 0;
	  break;
	}
	ch = st.top();
	if(ch != '(') {
	  ok = 0;
	  break;
	}
	st.pop();
      }
      
      if(s[i] == ']') {
	if(!i) {
	  ok = 0;
	  break;
	}
	ch = st.top();
	if(ch != '[') {
	  ok = 0;
	  break;
	}
	st.pop();
      }
    }
    cout << ( ok ? "yes" : "no" ) << endl;
  }
  
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int tail,c1,c2;
	char str[102];
	int f[102]={0};
	char *s;
	while(1){
		tail=1;
		fgets(str,102,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;
}

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

int main() {
  string s;

  while(getline(cin, s)) {
    if(s[0] == '.') break;
    bool b = true;
    int x = 0, y = 0;
    char c[1000];
    int top = 0;

    for(int i = 0; i < s.size(); i++) {
      if(s[i] == '(') {
	x++;
	c[top] = s[i];
	top++;
      }
      else if(s[i] == ')') {
	x--, top--;
	if(c[top] != '(') {
	  //cout << c[top] << ' ' << s[i] << endl;
	  b = false;
	  break;
	}
      }
      else if(s[i] == '[') {
	y++;
	c[top] = s[i];
	top++;
      }
      else if(s[i] == ']') {
	y--, top--;
	if(c[top] != '[') {
	  //cout << c[top] << ' ' << s[i] << endl;
	  b = false;
	  break;
	}
      }
      if(x < 0 || y < 0) {
	//cout << x << ' ' << y << endl;
	b = false;
	break;
      }
    }
    if(x == 0 && y == 0 && b) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

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

using namespace std;

int main(){
		char a[110];
		while(fgets(a,110,stdin),*a-'.'){
				int n=strlen(a);
				if(a[n-1]=='\n')a[--n]='\0';
				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 cout<<"no"<<endl;
		}
		return 0;
}

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

using namespace std;

int main() {
	string str;
	while ( getline(cin, str), str != "." ) {
		int k = 0, K = 0;
		stack<int> last;
		bool ans = true;
		for (int i = 0; i < str.size(); ++i) {
			switch (str[i]) {
				case '(':
					++k;
					last.push(0);
					break;

				case ')':
					if (last.empty() || last.top() != 0) {
						ans = false;
					}
					else {
						if (--k < 0) ans = false;
						last.pop();
					}
					break;

				case '[':
					++K; last.push(1);
					break;

				case ']':
					if (last.empty() || last.top() != 1) {
						ans = false;
					}
					else {
						if (--K < 0) ans = false;
						last.pop();
					}
					break;
			}
		}
		if (ans) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

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

void solve(string s){
    stack<char> stk;
    for(char c:s){
        if(c=='('){
            stk.push('(');
        }
        if(c=='['){
            stk.push('[');
        }
        if(c==')'){
            if(!stk.empty()&&stk.top()=='(')stk.pop();
            else {cout<<"no"<<endl;return;}
        }
        if(c==']'){
            if(!stk.empty()&&stk.top()=='[')stk.pop();
            else {cout<<"no"<<endl;return;}
        }
    }
    cout<<"yes"<<endl;
}

int main (){
    string s;
    while(getline(cin,s),s[0]!='.'&&s.size()!=1){
        solve(s);
    }
}