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 <stack>
using namespace std;

int main()
{
	string str;
	while (getline(cin, str)) {
		if (str == ".") {
			break;
		}
		stack<char> s;
		bool balanced = true;
		for (int i = 0; i < str.length(); ++i) {
			char c = str[i];
			switch (c) {
				case '(':
				case '[':
					s.push(c);
					break;
				case ')':
				case ']':
					if (s.empty()) {
						balanced = false;
					} else {
						char open = c == ')' ? '(' : '[';
						if (s.top() != open) {
							balanced = false;
						}
						s.pop();
					}
					break;
				default:
					break;
			}
		}
		if (!s.empty()) {
			balanced = false;
		}
		cout << (balanced ? "yes" : "no") << endl;
	}
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()

bool solve(string& s){
    s.erase(remove_if(all(s), [](char c){return string("()[]").find(c) == string::npos;}), s.end());
    vector<char> st;
    for(auto c: s){
        if(c == '(' || c == '[')st.push_back(c);
        else if(st.empty() || st.back() != (c == ')'? '(': '['))return false;
        else st.pop_back();
    }
    return st.empty();
}

vector<string> split(const string& in, char delim){
    istringstream stream(in);
    string field;
    vector<string> res;
    while(getline(stream, field, delim) && !field.empty())res.push_back(field);
    return res;
}

int main(){
    string buf = "";
    for(string line; getline(cin, line); line.erase(remove(all(line), '\n'), line.end()), buf += line);
    for(auto s: split(buf, '.'))cout << (solve(s)? "yes\n": "no\n");
    return 0;
}

C++: //
//  main.cpp
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    
    
    while(1){
        string yn = "yes";
        string str;
        vector<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push_back(str[i]);
            }
            
            if (str[i] == ')') {
                
                
                if ('(' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }

            if (str[i] == ']') {
                
                if ('[' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }

        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}

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

int main() {
    string s;
    while (getline(cin, s)) {
        if (s == ".") break;
        stack<char> st;
        st.push('@');
        for (char c : s) {
            if (st.top() == '(' && c == ')') {
                st.pop();
            } else if (st.top() == '[' && c == ']') {
                st.pop();
            } else if (c == '(' || c == '[' || c == ')' || c == ']') {
                st.push(c);
            }
        }
        if ((int)st.size() == 1) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

stack<int> st;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        stack<int> st;
        bool ans=true;
        int n=s.size();
        --n;
        int c1=0,c2=0;
        rep(i,n){
            if(s[i]=='('){
                ++c1;
                st.push(0);
            }
            else if(s[i]=='['){
                ++c2;
                st.push(1);
            }
            else if(s[i]==')'){
                --c1;
                if(c1<0||st.top()==1) ans=false;
                st.pop();
            }
            else if(s[i]==']'){
                --c2;
                if(c2<0||st.top()==0) ans=false;
                st.pop();
            }
            if(!ans) break;
        }
        if(ans) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;main(){int i,f,c;for(string s;getline(cin,s),s[0]-'.';){stack<char> t;for(f=i=0;c=s[i],c!='.';i++){if(c==40||c==91)t.push(c);if(c==41||c==93){if(!t.empty()&&(c-t.top()<3))t.pop();else f=1;}}puts(!f&&t.empty()?"yes":"no");}}

C++: #include <iostream>
#include <string>
#include<vector>
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&&v.back()!=1){
					IsOk = false;
				}
				else if (v.empty() == false){
					v.pop_back();
				}
			}
			else if (a[i] == 91){//[
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (v.empty() == false && v.back() != 0){
					IsOk = false;
				}
				else{
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (v.empty()==false){
					IsOk = false;
				}
				if (IsOk == true){cout << "yes"<<endl;
				}else{            cout << "no" <<endl;}
				IsOk = true; 
				v.clear();
				IsFinish = true;
			}
		}
	}
	return 0;
}