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 <vector>
#include <algorithm>
#include <string>
#include <stack>

using namespace std;

int main(){

	string str;
	while(getline(cin,str)&&str!="."){
		stack<char> s;
		bool f=true;

		for(int i = 0; i < str.size(); i++){
			if(str[i]=='('){
				s.push(str[i]);
			}
			else if(str[i]==')'){
				if(s.empty()){
					f=false;
					break;
				}
				else{
					if(s.top()=='(')
						s.pop();
					else{
						f=false;
						break;
					}
				}
			}
			else if(str[i]=='['){
				//s2.push(1);
				s.push(str[i]);
			}
			else if(str[i]==']'){
				if(s.empty()){
					f=false;
					break;
				}
				else{
					if(s.top()=='['){
						s.pop();
					}
					else{
						f=false;
						break;
					}
				}
			}
		}
		if(f&&s.size()==0)
			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),s!="."){
    stack<char> a;
    bool flag=false;
    for(int i=0;i<s.size();++i){
      if(s[i]=='(' || s[i]=='[') a.push(s[i]);
      else if(s[i]==')')
        if(a.empty() || a.top()!='(') flag=true;
        else a.pop();
      else if(s[i]==']')
        if(a.empty() || a.top()!='[') flag=true;
        else a.pop();
      if(flag) break;
    }
    if(flag || !a.empty()) cout<<"no\n";
    else cout<<"yes\n";
  }
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FORR(i,a,b) for (int i=a; i>=b; i--)

typedef long long ll;

int main(void){
	string str;

	while(getline(cin,str)){
		if (str.size()==1 && str[0]=='.') break;
		bool f=1;
		stack<int> st;
		REP(i,str.length()){
			switch(str[i]){
				case '(' :
					st.push(0);
					break;
				case '[' :
					st.push(1);
					break;
				case ')' :
					if (st.top()==0)
						st.pop();
					else
						f=0;
					break;
				case ']' :
					if (st.top()==1)
						st.pop();
					else
						f=0;
					break;
			}
		}

		if (f)
			cout << "yes" << endl;
		else 
			cout << "no" << endl;
	}
	

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	string a;
	bool IsOk = true;
	bool b = false;
	bool IsFinish = false;
	vector<int> v;
	while (cin >> a){
		if (IsFinish==true&&a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}else{
			b = false;
			IsFinish = false;
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (v.empty() == false){
					if (v.back() != 1){
						IsOk = false;
					}
					v.pop_back();
				}
				else{
					IsOk = false;
				}
				
			}
			else if (a[i] == 91){//[
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (v.empty() == false){
					if (v.back() != 0){
						IsOk = false;
					}
					v.pop_back();
				}
				else{
					IsOk = false;
				}
			}
			else if (a[i] == 46){//.
				if (!v.empty()){
					IsOk = false;
				}
				if (IsOk == true){cout << "yes"<<endl;
				}else{            cout << "no" <<endl;}
				IsOk = true; 
				v.clear();
				IsFinish = true;
			}
		}
	}
	return 0;
}

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

int main(){
    //freopen ("/Users/shitian/Downloads/1173-in1.txt","r",stdin);
    char f[102];int c=0,d=0;
    while(1){
        stack<char>s;
        c=0;d=0;
        cin.getline (f,156);
        if(f[0]=='.')
            return 0;
        for(int i=0;f[i]!='.';i++){
            if(f[i]=='('){
                c++;s.push('(');
            }
            if(f[i]==')'){
                c--;
                if(s.size()==0){
                    cout<<"no"<<endl;
                    goto next;
                }
                if(s.top()!='('){
                    cout<<"no"<<endl;
                    goto next;
                }
                s.pop();
            }
            if(f[i]=='['){
                d++;s.push('[');
            }
            if(f[i]==']'){
                if(s.size()==0){
                    cout<<"no"<<endl;
                    goto next;
                }
                if(s.top()!='['){
                    cout<<"no"<<endl;
                    goto next;
                }
                d--;
                s.pop();
            }
            if(c<0||d<0){
                cout<<"no"<<endl;
                goto next;
            }
        }
        if(c==0&&d==0)
            cout<<"yes"<<endl;
        else
            cout<<"no"<<endl;next:;
    }
    return 0;
}

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

int si = 0;
string S;
bool parse(char c)
{
  bool fail = false;
  for(; si < S.length(); si++)
  {
    if(S[si] == c)
      return true;
    switch(S[si])
    {
      case '(':
        si++;
        fail = !parse(')');
        break;
      case '[':
        si++;
        fail = !parse(']');
        break;
      case ']': case ')':
        fail = true;
    }
    if(fail)
      return false;
  }
  return false;
}

int main()
{
loop:
  si = 0;
  getline(cin, S);
  if(S == ".")
    return 0;
  cout << (parse('.') ? "yes" : "no") << endl;
  goto loop;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)

using namespace std;

int main(void){
	for(string in; getline(cin, in) && in != ".";){
		stack<char> table;
		string out = "yes";

		rep(i, in.length()){
			char curChar = in.at(i);
			if(curChar == '[' || curChar == '(') table.push(curChar);
			else if(curChar == ']'){
				if(!table.empty() && table.top() == '[') table.pop();
				else{ out = "no"; break; }
			}
			else if(curChar == ')'){
				if(!table.empty() && table.top() == '(') table.pop();
				else{ out = "no"; break; }
			}
		}
		cout << out << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
using namespace std;
string s;
bool solve() {
  stack<char> st;
  for(int i = 0; i < (int)s.length(); ++i) {
    if(s[i] == '[') st.push(s[i]);
    if(s[i] == ']') {
      if(st.top() != '[') return 0;
      st.pop();
    }
    if(s[i] == ')') {
      if(st.top() != ')') return 0;
      st.pop();
    }
  }
  return st.empty();
}

int main() {
  while(getline(cin, s)) {
    if(s == ".") break;
    cout << (solve() ? "yes" : "no") << endl;
  }
  return 0;
}