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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	string s;
	while(1)
	{
		getline(cin,s);
		if(s==".")break;
		stack<string> st;
		int len=s.size();
		for(int i=0;i<len;i++)
		{
			string tmp;
			tmp+=s[i];
			if(s[i]=='('||s[i]=='[')st.push(tmp);
			if(s[i]==')')
			{
				if(st.empty())
				{
					cout << "no" << endl;
					goto end;
				}
				string p=st.top();
				st.pop();
				if(p!="(")
				{
					cout << "no" << endl;
					goto end;
				}
			}
			if(s[i]==']')
			{
				if(st.empty())
				{
					cout << "no" << endl;
					goto end;
				}
				string p=st.top();
				st.pop();
				if(p!="[")
				{
					cout << "no" << endl;
					goto end;
				}
			}
		}
		if(!st.empty())
		{
			cout << "no" << endl;
			goto end;
		}
		cout << "yes" << endl;
		end:;
	}
	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
using namespace std; 
int main(){
  string s;
  while(getline(cin,s),s!="."){
    stack<int> a;
    for(int i=0;i<s.size();i++){
      if(s[i]=='('||s[i]=='['){
	a.push(s[i]);
      }
      else if(s[i]==')'){
	if(a.size()>0&&a.top()=='('){
	  a.pop();
	}else{
	  cout<<"no"<<endl;
	  goto at;
	}
      }
      else if(s[i]==']'){
	if(a.size()>0&&a.top()=='['){
	  a.pop();
	}else{
	  cout<<"no"<<endl;
	  goto at;
	}
      }
    }
    if(a.size()==0){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  at: ;  
}
  
  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]);
            else if(c[i]==']'&&w.top()=='['||c[i]==')'&&w.top()=='(')w.pop();
            else break;
        }
        if(w.empty())cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

bool balanced(string s)
{
    deque<char> deq;
    for(string::iterator itr = s.begin(); itr!=s.end(); itr++)
    {
        switch(*itr)
        {
            case '(':
                deq.push_back(')');
                break;
            case '[':
                deq.push_back(']');
                break;
            case ')':
            case ']':
                if(deq.empty() || deq.back() != *itr) return false;
                deq.pop_back();
                break;
        }
    }
    return true;
}

int main()
{
    string s;
    while(getline(cin, s), s!=".")
    {
        cout << (balanced(s) ? "yes" : "no") << endl;
    }
}

C++: #include <cstdio>
#include <string>

int main() {
	int i, j;
	char t[101], c, st[101];
	while (true) {
		for (i = 0; ~scanf("%c", &c) && c != '\n'; i++) {
			t[i] = c;
		}
		t[i] = 0;
		if (t[0] == '.' && t[1] == 0) {
			return 0;
		} 
		memset(st, 0, sizeof st);
		for (i = 0, j = 0; i <= strlen(t); i++) {
			if (t[i] == '(' || t[i] == '[') {
				st[j++] = t[i];
			}
			if (t[i] == ')') {
				if (st[--j] != '(') {
					puts("no");
					break;
				}
			}
			if (t[i] == ']') {
				if (st[--j] != '[') {
					puts("no");
					break;
				}
			}
			if (t[i] == 0) {
				puts("yes");
			}
		}
	}
	return 0;
}

C++: //
//  main.cpp
//  AOJ1173
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;

string S;
void solve(){
    int a = 0, b = 0;
    char last = '.';
    
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c == '('){
            last = '(';
            a++;
        }else if(c == ')'){
            a--;
            last = ')';
            if(last == '[' || a < 0){
                cout << "no" << endl;
                return;
            }
        }else if(c == '['){
            last = '[';
            b++;
        }else if(c == ']'){
            b--;
            last = ']';
            if(last == '(' || b < 0){
                cout << "no" << endl;
                return;
            }
        }
    }
    cout << "yes" << endl;
}

int main(int argc, const char * argv[])
{
    while(1){
        S = "";
        string s;
        cin >> s;
        if(s == ".")
            break;
        S += s;
        while(1){
            cin >> s;
            S += s;
            if(s[s.size()-1] == '.')
                break;
        }
        solve();
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include <cstdio>
#include<cstdlib>
using namespace std;
const int limit=200;
char st[limit];
int a[limit];
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int aa;
	gets(st);
	int n=strlen(st);
	while (!((st[0]=='.')&&(n==1)))
	{
		for(int i=0;i<=n;i++)
		{
			if(st[i]=='[') a[++aa]=1;
			else if(st[i]==']') a[++aa]=2;
			else if(st[i]=='(') a[++aa]=3;
			else if(st[i]==')') a[++aa]=4;	
		}	
		bool ok=true;
		while ((ok)&&(aa>0))
		{
			ok=false;
			for (int i=1;i<=aa-1;i++) if(((a[i]==1)&&(a[i+1]==2))||((a[i]==3)&&(a[i+1]==4)))
			{
				for(int j=i;j<=aa-2;j++) a[j]=a[j+2];
				a[aa]=0; a[aa-1]=0;
				aa=aa-2;
				ok=true;
				break;
			}
		}
		if(aa==0) cout<<"yes";
		else cout<<"no";
		cout<<endl;
		for(int i=1;i<=aa;i++) a[i]=0;
		aa=0;
		gets(st);
		n=strlen(st);
	}		
}