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<algorithm>
#include<stdio.h>
using namespace std;

int main() 
{
	string s;
	while(true)
	{
		getline(cin,s);
		if(s==".")return 0;
		string t;
		//int len=s.size();
	//	cout<<0<<endl;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]==' ')s.erase(s.begin()i);
		}
		cout<<s<<endl;
		t=s;
		for(int i=0;i<s.size();i++)
		{
		//	cout<<0<<endl;
			if(s[i]=='(')
			{
				for(int j=s.size()-1;i<j;j--)
				{
					if(s[j]==')')
					{
						t.erase(i);
						t.erase(j);
					}
				}
			}
			if(s[i]=='[')
			{
				for(int j=s.size()-1;i<j;j--)
				{
					if(s[j]==']')
					{
						t.erase(i);
						t.erase(j);
					}
				}
			}
		}
	//	cout<<0<<endl;
		for(int i=0;i<t.size();i++)
		{
			if(t[i]=='('||t[i]==')'||t[i]=='['||t[i]==']')
			{
				cout<<"no"<<endl;
				goto A;
			}
		}
		cout<<"yes"<<endl;
		A:;
		s.clear();
		t.clear();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;

int main() {
    string str;

    while (true) {
        getline(cin, str);
        if (str == ".") break;

        bool flag=true;
        for (int i=str.size()-1; i>=0; --i) {
            if (str[i] == '(' or str[i] == '[') {
                int t=(str[i] == '(' ? 1 : 0);
                str[i]='.';
                flag=false;
                for (int j=i+1; j<str.size(); ++j) {
                    if (str[j] == ')' and t) {
                        str[j]='.';
                        flag=true;
                        break;
                    }
                    else if (str[j] == ')' and !t) {
                        break;
                    }
                    else if (str[j] == ']' and !t) {
                        str[j]='.';
                        flag=true;
                        break;
                    }
                    else if (str[j] == ']' and t) {
                        break;
                    }
                }
            }
            if (!flag) break;
        }
        cout << (flag ? "yes" : "no") << endl;
    }

}

C++: #include "limits"
#include "algorithm"
#include "iostream"
#include "cmath"
#include "string"
#include "map"
#include "iomanip"
#include "stack"
using namespace std;

int main(){
  char S[110];
  bool FLAG;
  stack<char> temp;
  while(1){
    FLAG=true;
    gets(S);
    if(S[0]=='.')break;
    for(int i=0;S[i]!='.';++i){
      if(S[i]=='(' || S[i]=='[')temp.push(S[i]);
      if(S[i]==')'){
        if(temp.empty()){
          FLAG=false;
          break;
        }
        char a=temp.top();
        temp.pop();
        if(a!='('){
          FLAG=false;
          break;
        }

      }
      if(S[i]==']'){
        if(temp.empty()){
          FLAG=false;
          break;
        }
        char a=temp.top();
        temp.pop();
        if(a!='['){
          FLAG=false;
          break;
        }
      }
    }
    if(FLAG)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
}

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

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

C++: #include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, a, n) for(int i = (a);i < (n);i++)
#define REP(i, n)    rep(i, 0, n)
#define all(e)       (e).begin(), (e).end()

#ifdef LOCAL
#define show(x) cerr<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#else
#define show() true
#endif

using namespace std;
using ll=long long;
template<class T> using V=vector<T>;

template<class T, class U>
void chmin(T &t, const U u) { if (t > u) t = u; }

template<class T, class U>
void chmax(T &t, const U u) { if (t < u) t = u; }

const int INF = (1 << 30) - 1;
const ll INFL = (ll) 5e15;
const int MOD = 1000000007;

class Solver {
public:
    bool solve() {
        getline(cin, S);

        if (S == ".") return false;

        for (auto c:S) {
            if (c == '(') {
                kakko.push(c);
            }
            if (c == '[') {
                kakko.push(c);
            }
            if (c == ')') {
                if (kakko.empty() || kakko.top() != '(') {
                    puts("no");
                    return true;
                } else {
                    kakko.pop();
                }
            }
            if (c == ']') {
                if (kakko.empty() || kakko.top() != '[') {
                    puts("no");
                    return true;
                } else {
                    kakko.pop();
                }
            }
        }

        puts(kakko.empty() ? "yes" : "no");

        return true;
    }

private:
    string S;
    stack<char> kakko;
};

int main() {

    while (Solver().solve());

    return 0;
}

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

int main(void){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool flag=false;
    for(int i=0;i<c.length();i++){
      if(s.empty() || c[i]=='(' || c[i]=='[')s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']'))s.pop();
      else {flag=true;break;}
    }
    cout << (flag==false&&s.empty()?"YES":"NO") << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int main(){
  while(1){
    string s; getline(cin, s);
    if(s==".") break;
    stack<char> st;
    bool flag=1;
    rep(i,s.length()){
      if(s[i]=='(') st.push('(');
      if(s[i]=='[') st.push('[');
      if(s[i]==')'){
        if(st.empty()) flag=0;
        else if(st.top()=='(') st.pop();
        else flag=0;
      }
      if(s[i]==']'){
        if(st.empty()) flag=0;
        else if(st.top()=='[') st.pop();
        else flag=0;
      }
    }
    if(flag and st.empty()) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}