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<string>
#include<cctype>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int search(vector<char> &v, char c){
    for(int j = v.size() - 1; j >= 0; j--){
        if(v[j] == c) return j;
    }
    return -1;
}

int main(){
    string str;
    while(getline(cin, str)){
        if(str == ".") break;
        bool OKflg = true;
        vector<char> v;
        REP(i, str.length()){
            if(str[i] == '(') v.push_back('(');
            else if(str[i] == '[') v.push_back('[');
            else if(str[i] == ')'){
                int tmp = search(v, '(');
                if(tmp == -1){
                    OKflg = false;
                    break;
                } else REP(j, v.size() - tmp + 1) v.pop_back();
            }
            else if(str[i] == ']'){
                int tmp = search(v, '[');
                if(tmp == -1){
                    OKflg = false;
                    break;
                } else REP(j, v.size() - tmp + 1) v.pop_back();
            }
        }
        if(OKflg && v.size() == 0) cout <<"yes" <<endl;
        else cout <<"no" <<endl;
    }
    return 0;
}

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

int main () {
    string str;
    map<char,char> c;
    c[']'] = '[';
    c[')'] = '(';
    while (getline(cin,str), str != ".") {
        stack<char> s;
        bool flag = true;
        for (int i = 0; flag && i < str.size(); i++) {
            if (string("[(").find(str[i]) != string::npos) {
                s.push(str[i]);
            }
            else if (string("])").find(str[i] != string::npos)) {
                if (s.size() == 0) flag = false;
                else if (c.find(str[i]) != c.end() && c[str[i]] == s.top()) s.pop();
                else if (c.find(str[i]) != c.end() && c[str[i]] == s.top()) s.pop();
                else flag = false;
            }
        }

        cout << (flag && !s.size() ? "yes" : "no") << endl;
    }
}

C++: #include"iostream"
#include"fstream"
#include"stack"
#include"string"

using namespace std;

int main(){

	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp

	ifstream fin;
	ofstream fout;

	fin.open("input.txt");
	fout.open("output.txt");

	//http://www.cppll.jp/cppreference/cppstack_details.html
	//empty()関数は現在のスタックが空の時にtrueを返し、そうでないときはfalseを返す 

	string a;

	stack<char> s;
	bool yes = true;

	while (true){
		yes = true;

		getline(cin, a);

//		cout << a << endl;

//		if (a[0] == ' ')
//			cout << "ファーーーwww" << endl;
		if (a[0] == '.')break;

		for (int i = 0; i < 100; i++){
			if (a[i] == '(' || a[i] == '['){
				s.push(a[i]);
				yes = false;
			}
			if (a[i] == ')'){
				if (!s.empty()){
					if (s.top() == '('){
						yes = true;
						s.pop();
					}
					else {
						yes = false;
						break;
					}
				}
				else {
					yes = false;
					break;
				}
			}
			if (a[i] == ']'){
				if (!s.empty()){
					if (s.top() == '['){
						yes = true;
						s.pop();
					}
					else {
						yes = false;
						break;
					}
				}
				else {
					yes = false;
					break;
				}
			}
			//			if (!s.empty())
			//				cout << a[i] << "  :  " << s.top() << "  :  " << yes << endl;
			//			else cout << "topエラー" << endl;

			if (a[i] == '.')break;
		}

		if (yes == true){
//			cout << "yes" << endl;
			fout << "yes" << endl;
		}
		else{
//			cout << "no" << endl;
			fout << "no" << endl;
		}
		while (!s.empty())s.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
// #define INF
// #define mp
// #define pb

// #define fi
// #define se

// #define each

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	while(1){
		stack <char> st;
		string s = "";
		char q;
		q = getchar();
		//cout<<q<<endl;
		if(q=='.') return 0;
		s += q;

		while(1){
			string c;
			cin>>c;
			if(c[c.size()-1]!='.') s+= (' '+c);
			else{
				s += (' '+c);
				break;
			}
		}
		//cout<<s<<endl;
		if(s[0]=='.'&& s.size()==1) break;
		rep(i,s.size()){
			switch(s[i]){
				case '[': st.push('[');
				break;
				case '(': st.push('(');
				break;
				case ']': 
					if(st.empty()){
						cout << "no" << endl;
						goto END;
					}
					if(st.top()!='['){
						cout << "no" << endl;
						goto END;
					}else{
						st.pop();
					}
				break;
				case ')':
					if(st.empty()){
						cout << "no" << endl;
						goto END;
					}
					if(st.top()!='('){
					cout << "no" << endl;
					goto END;
					}else{
						st.pop();
					}
				break;
			}
		}
		if(!st.empty()) cout <<"no"<<endl;
		else cout << "yes"<<endl;
		END:;
	}
	return 0;
}

C++: ##include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
	while(1){
		bool flag;
		flag = true;
		string str;
		stack<int> num;
		getline(cin,str);
		if(str==".")	break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='[')	num.push(1);
			else if(str[i]==']'){
				if(num.top()==1)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]==')'){
				if(num.top()==2)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]=='(')	num.push(2);
			
		}
		if(num.size()==0&&flag)	cout << "yes\n";
		else	cout << "no\n";
	}
}

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

#define int long long

char* Solve(string S)
{
    stack<char> s;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '(') s.push(')');
        else if (S[i] == '[') s.push(']');
        else if (S[i] == ')' || S[i] == ']')
        {
            if (s.empty() || s.top() != S[i]) return "no";
        }
    }
    if (!s.empty()) return "no";
    return "yes";
}

signed main()
{
    string S;
    while (getline(cin, S), S != ".")
    {
        printf("%s\n", Solve(S));
    }
    return 0;
}