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;

int main(){
    char s[108];
    stack<char> stk;
    cin.getline(s, 101);
    while(s[0] != '.' && s[1] != '\0'){
        int rnd = 0, box = 0, no = 0;
        for(int i = 0; i < sizeof(s); i++){
            if(s[i] == '(') stk.push('(');
            if(s[i] == '[') stk.push('[');
            if(s[i] == ')'){
                if(stk.empty() || stk.top() != '('){
                    no = 1;
                    break;
                }
                stk.pop();
            }
            if(s[i] == ']'){
                if(stk.empty() || stk.top() != '['){
                    no = 1;
                    break;
                }
                stk.pop();
            }
            if(s[i] == '\0') break;
        }
        if(no == 0 && rnd == 0 && box == 0){
            printf("yes\n");
        } else {
            printf("no\n");
        }
        while(!stk.empty()){
            stk.pop();
        }
        cin.getline(s, 101);
    }
}

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

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

C++: #include <stdio.h>
int main() {char Tex[105];int i=0,j,k=0;bool one_per=false;while (1) {k++;Tex[i]=getchar();if (Tex[i]=='(' || Tex[i]=='[') i++,one_per=false; else if (Tex[i]==')') {j=(i)?i-1:0;i+=(Tex[j]=='(')?-1:1;one_per=false;}
    else if (Tex[i]==']') {j=(i)?i-1:0;i+=(Tex[j]=='[')?-1:1;one_per=false;} else if (Tex[i]=='.' && k==1) one_per=true; else if (Tex[i]=='\n' || Tex[i]==EOF) {if (one_per==true) return 0;if (i) puts("no"); else puts("yes");k=0,i=0,one_per=false;}}}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  string str;
  string tmp;
  while(getline(cin, str) && str != "."){
    int p = 0, q = 0;
    bool flag = 1;
    tmp = "";
    
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '[' || str[i] == '(' || str[i] == ']' || str[i] == ')'){
	tmp += str[i];
      }
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' && tmp[i+1] == ']') flag = 0;
      if(tmp[i] == '[' && tmp[i+1] == ')') flag = 0;
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      //printf("p = %d, q = %d\n", p, q);
      if(p < 0 || q < 0){
	flag = 0;
	break;
      }
      if(tmp[i] == '(') p++;
      if(tmp[i] == '[') q++;
      if(tmp[i] == ')') p--;
      if(tmp[i] == ']') q--;
    }
    if(p != 0 || q != 0) flag = 0;
    
    if(flag == 1) cout << "yes" << endl;
    else cout << "no" << endl;    
  }
  return 0;
}

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

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

    string s;
    for(unsigned i=0; i<str.size(); i++)
      if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
	s.push_back(str[i]);
    
    stack<char> st;
    bool ok = 1;
    for(int i=0; i<s.size(); i++) {
      if(s[i] == '(') st.push(s[i]);
      if(s[i] == '[') st.push(s[i]);
      
      if(s[i] == ')') {
	if(st.empty()) { ok = 0; break; }
	if(st.top() != '(') { ok = 0; break; }
	st.pop();
      }
      
      if(s[i] == ']') {
	if(st.empty()) { ok = 0; break;	}
	if(st.top() != '[') { ok = 0; break; }
	st.pop();
      }
    }
    cout << ( ok && st.empty() ? "yes" : "no" ) << endl;
  }
  
  return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)

string solve(string s)
{
	stack<char> _stack;
	rep(i, 0, s.length())
	{
		switch (s[i])
		{
		case '(':
		case '[':
			_stack.push(s[i]);
			break;

		case ')':
			if (_stack.empty()) return "no";
			if (_stack.top() != '(') return "no";
			_stack.pop();
			break;

		case ']':
			if (_stack.empty()) return "no";
			if (_stack.top() != '[') return "no";
			_stack.pop();
			break;
		}
	}
	if (_stack.empty())
		return "yes";
	else
		return "no";
}

int main()
{
	while (1)
	{
		string s;
		getline(cin, s);
		if (s.length() == 1) return 0;

		cout << solve(s) << endl;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int kako[110];
string str;

void g(){
	int c;
	str="";
	while(c=getchar(),c<' ');
	while(c>=' '){
		str+=(char)c;
		c=getchar();
	}
}

int main() {
	while(g(),str[0]!='.'){
//cout<<str<<endl;
		int i;
		int k=0;
		string res="yes";
		for(i=0;i<str.size();i++){
			if(str[i]=='[')kako[k++]=1;
			else if(str[i]=='(')kako[k++]=2;
			else if(str[i]==']'){
				if(k==0||kako[k-1]!=1){
					res="no";
					break;
				}
				k--;
			}else if(str[i]==')'){
				if(k==0||kako[k-1]!=2){
					res="no";
					break;
				}
				k--;
			}
		}
		if(k!=0)res="no";
		cout<<res<<endl;
	}
	return 0;
}

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

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

      stack<char> stk;
      bool ok = true;
      int n = s.size();
      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.empty() || stk.top() != '(') {
               ok = false;
               break;
            }
            stk.pop();
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = false;
               break;
            }
            stk.pop();
         }
      }
      if (stk.empty() && ok) {
         puts("yes");
      } else {
         puts("no");
      }
   }
}