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>
#include <vector>
using namespace std;
int main()
{
	string str;
	while( getline(cin,str) && str != "." ){
		string z;
		for(int i=0;i<str.size();i++)
			if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']')
				z+=str[i];
		stack<char> s;
		bool f = true;
		for(int  i=0;i < z.length();i++){
			if( z.empty() || z[i] == '(' || z[i] == '[' ){
				s.push(z[i]);
			}else if( (s.top() == '(' && z[i] == ')') || (s.top() == '[' && z[i] == ']') )
				s.pop();
			else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ? "yes": "no")  << endl;
	}

	return 0;
}

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

int main()
{
  string line;
  while (getline(cin, line)) {
    if (line.find_first_of("\n") != string::npos)
      line.erase(line.end()-1);
    if (line.find_first_of("\r") != string::npos)
      line.erase(line.end()-1);

    if (line == ".")
      break;

    bool yes = true;
    stack<char> stk;
    for (unsigned int i = 0; i < line.size() && yes; ++i) {
      if (line[i] == '(') {
	stk.push('(');
      } else if (line[i] == ')') {
	if (stk.empty() || stk.top() != '(')
	  yes = false;
	else
	  stk.pop();
      } else if (line[i] == '[') {
	stk.push('[');
      } else if (line[i] == ']') {
	if (stk.empty() || stk.top() != '[')
	  yes = false;
	else
	  stk.pop();
      }
    }

    if (yes && stk.empty())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
  return 0;
}

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

using namespace std;

void load(vector<string>& datas){
    while(1){
        string str;
        while(1){
            char word;
            if(!cin){
                datas.pop_back();
                datas.pop_back();
                return;
            }
            cin >> word;
            str += word;
            if(word == '.') break;
        }
        datas.push_back(str);
    }
}



int main()
{
    vector<string> datas;
    
    load(datas);
    
    for(auto data: datas){
        vector<bool> brackets;
        
        for(auto itr = data.begin(); itr != data.end(); itr++){
            if(*itr == '[') brackets.push_back(true);
            else if(*itr == '(') brackets.push_back(false);
            else if(*itr == ']' && brackets.size()) {
                if(brackets.back() == true) 
                    brackets.pop_back();
            }
            else if(*itr == ')' && brackets.size()) {
                if(brackets.back() == false) 
                    brackets.pop_back();
            }
        }
        if(brackets.size()) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	while(1){
		getline(cin,s);
		if(s==".")break;
		stack<char> st;
		bool ans = true;
		FOR(i,0,s.size()){
			if(s[i]=='('||s[i]=='['){
				st.push(s[i]);
			}else if(s[i]==')'){
				if(st.size()==0){
					ans = false;
				}else{
					if(st.top()=='(')st.pop();
					else ans = false;
				}
			}else if(s[i]==']'){
				if(st.size()==0){
					ans = false;
				}else{
					if(st.top()=='[')st.pop();
					else ans = false;
				}	
			}
		}
		if(ans){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
}

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


bool dfs(string s){
//    cout << "dfs :" << s << endl;
    if(s=="") return true;

    vector<string> vs;
    string ss;
    int a=0,b=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='(') a++;
        else if(s[i]==')') a--;
        else if(s[i]=='[') b++;
        else if(s[i]==']') b--;
        ss += s[i];
        if(i!=0 && a==0 && b==0){
            vs.push_back(ss);
            ss="";
        }
    }

    if(a!=0 || b!=0){
//        cout << "a or b is not 0" << endl;
        return false;
    }

//    cout << " vs " << endl;
//    for(auto v : vs){
//        cout << v << endl;
//    }

    for(int i=0;i<vs.size();i++){
        string t = vs[i];
        char s = t[0];
        char e = t[t.size()-1];
        if(!((s=='('&&e==')')||(s=='['&&e==']'))){
//            cout << " not match " << endl;
            return false;
        }
        if(!dfs(t.substr(1,t.size()-2))){
//            cout << "dfs is not true" << endl;
            return false;
        }
    }
    return true;
}

void solve(string s){
    string ss;
    for(char c : s) if(c=='[' || c==']' || c=='(' || c==')') ss += c;

//    cout << ss << endl;
    bool f = dfs(ss);
    if(f) cout << "yes" << endl;
    else cout << "no" << endl;
}

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

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

int main() {
	string b;
	int i, c = 0, d = 0;
	stack<char> a;
	bool e;
	while (1) {
		getline(cin,b);
		for (i = 0; i<(int)b.size(); i++) {
				/*if (b[i] == '(') { c += 1; 
				e = true;
				}
				if (b[i] == ')') {
					c -= 1;
					e = false;
					if (c < 0||e==false) {
						c = 1;
						break; }
				}
				if (b[i] == '[') { d += 1; 
				e = false;
				}
				if (b[i] == ']') { d -= 1;
				d = true;
				if (d < 0||e==true) { 
					d = 1;
					break;
				}
				}
		*/
			if (b[i] == '(' || b[i] == '[') {
				a.push(b[i]); }
			if (a.empty())if (b[i] == ')' || b[i] == ']') { 
				a.push(b[i]);
				break; }
			if (b[i] == ')'&&a.top() == '(') { a.pop(); }
			else if (b[i] == ']'&&a.top() == '[') { a.pop(); }
			else if (b[i] == ')'&&a.top() == '[') { break; }
			else if (b[i] == ']'&&a.top() == '(') { break; }

		}

		if (b[0] == '.') { break; }
		//if (c == 0 && d == 0) 
		if(a.empty()){cout << "yes"<<endl; }
			else { cout << "no"<<endl; }
			//c = 0, d = 0;
			while (!a.empty()) { 
			a.pop();
			};
	};
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        string c;
        int d=1;
        stack<char> w;
        for(int i=0;i<s.size();i++)if(s[i]==')'||s[i]=='('||s[i]=='['||s[i]==']')c+=s[i];
            for(int i=0;i<c.size();i++){
            if(c[i]=='['||c[i]=='(')w.push(c[i]);
            if(c[i]==']'&&w.top()=='['||c[i]==')'&&w.top()=='(')w.pop();
            else {d=0;break;}
        }
        if(d)cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}