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

int main(){
  vector < char > moji;
  string str;
  int i;
  while(getline(cin,str)){
    int flag = 0;
    int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
    if( str == "." ) break;
    
    int len = str.size();

    moji.clear();
      
    for( i = 0; i < len; i++ ){
      if( str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']'){
	if( str[i] == '(' ) cnt1++;
	if( str[i] == ')' ) cnt2++;
	if( str[i] == '[' ) cnt3++;
	if( str[i] == ']' ) cnt4++;

	moji.push_back(str[i]);
      }
    }
   
    if( cnt1 != cnt2 ) flag = 1;
    if( cnt3 != cnt4 ) flag = 1;
    
    int len2 = moji.size();
        
    for( i = 0; i < len2-1; i++ ){
      if( moji[0] == ')' ) flag = 1;
      if( moji[0] == ']' ) flag = 1;
      
      if( moji[i] == '[' && moji[i+1] == ')' ) flag = 1;
      if( moji[i] == '(' && moji[i+1] == ']' ) flag = 1;
    }

    if( flag == 0 ) cout << "yes" << endl;
    else if( flag == 1 ) cout << "no" << endl;

  }
  return 0;
}

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

int main(){
	string s;
	while( getline(cin,s) ){
		if( s == "." ) break;
		stack<char> st;
		bool flag = true;

		for(int i=0 ; i < s.size() ; i++ ){
			char c = s[i];
			if( c == '(' || c == '[' ){
				st.push( c );
			}else if( s[i] == ')' ){
				if( st.empty() || st.top() == '[' ){
					flag = false;
					break;
				}else if( st.top() == '(' ){
					st.pop();
				}
			}else if( s[i] == ']' ){
				if( st.empty() || st.top() == '(' ){
					flag = false;
					break;
				}else if( st.top() == '[' ){
					st.pop();
				}
			}
		}
		if( flag && st.empty() )
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,k,n) for(int i=k;i<(int)(n);i++)

#define vi vector<int>
#define pb push_back

typedef long long ll;


int main(){
//    ifstream in("bin.txt");
//    cin.rdbuf(in.rdbuf());
    string s;
    while(getline(cin,s),s[0]!='.'){
        bool flag = true;
        stack<char> st;
        rep(i,s.size()){
            switch(s[i]){
                case '(':
                    st.push('(');
                    break;
                case ')':
                    if(st.empty() || st.top()!='('){
                        flag = false;
                        i = s.size();
                    }else{
                        st.pop();
                    }
                    break;
                case '[':
                    st.push('[');
                    break;
                case ']':
                    if(st.empty() || st.top()!='['){
                        flag = false;
                        i = s.size();
                    }else{
                        st.pop();
                    }
                    break;
            }
        }
        if(st.empty() && flag) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
// stack
int main()
{
  string s;
  while(getline(cin, s)) {
    if(s[0] == '.' && s.length() == 1) return 0;
    stack<char> st;
    bool ok = true;
    FOR(i,0,s.length()) {
      if(s[i] == '(' || s[i] == '[') st.push(s[i]);
      if(s[i] == ')' || s[i] == ']') {
        if(st.empty()) {
          ok = false;
          break;
        }
        char c = st.top(); st.pop();
        if(s[i] == ')' && c == '[') {
          ok = false;
          break;
        }
        if(s[i] == ']' && c == '(') {
          ok = false;
          break;
        }
      }
    }
    if(!st.empty()) ok = false;
    puts(ok?"yes":"no");
  }
  return 0;
}

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

using namespace std;

int main(){
	int rk=0, sk=0, len=0;
	char in;
	bool check=false;
	stack<char> st;
	st.push(' ');
	while(true){
		scanf("%c", &in);
		if( in == '\n' ) continue;
		if( in == '.' && len == 0 ) break;
		len++;
		if( in == '(' ){ rk++; st.push('('); }
		if( in == '[' ){ sk++; st.push('['); }
		if( in == ')' ){
			if( --rk < 0 || st.top() != '(' )
				check=true;
			st.pop();
		}
		if( in == ']' ){
			if( --sk < 0 || st.top() != '[' )
				check=true;
			st.pop();
		}
		if( in == '.' ){
			cout << (check?"no":"yes") << endl;
			rk = 0;
			sk = 0;
			len = 0;
			check = false;
			while(st.empty()) st.pop();
			st.push(' ');
		}
	}
	return 0;
}

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

#include <iostream>

using namespace std;

bool check(string s,int *i,bool is_cir,bool is_squ)
{
    bool is_yes= true;

    while(is_yes && *i<s.length()) {
        if(s[*i]=='('){
            if(is_cir){
                is_yes = false;
            }else {
                check(s,i,true,is_squ);
            }
        }else if(s[*i]=='['){
            if(is_squ){
                is_yes = false;
            }else {
                check(s,i,is_cir,true);
            }
        }else if(s[*i]==')'){
            if(is_cir){
                check(s,i, false,is_squ);
            }else {
                is_yes = false;
            }
        }else if(s[*i]=='[') {
            if(is_squ){
                check(s,i,is_cir, false);
            }else {
                is_yes = false;
            }
        }
        (*i)++;
    }
    return is_yes;
}

int main()
{
    string s;

    while(getline(cin,s) && s!="."){
        bool is_yes= true;
        bool is_cir = false;
        bool is_squ = false;

        for (int i = 0; is_yes && i<s.length(); ++i) {
            if(s[i]=='('){
                if(is_cir){
                    is_yes = false;
                }else {
                    is_cir = true;
                }
            }else if(s[i]=='['){
                if(is_squ){
                    is_yes = false;
                }else {
                    is_squ = true;
                }
            }else if(s[i]==')'){
                if(is_cir){
                    is_cir = false;
                }else {
                    is_yes = false;
                }
            }else if(s[i]=='[') {
                if(is_squ){
                    is_squ = false;
                }else {
                    is_yes = false;
                }
            }
        }
        if(is_yes){
            cout<<"yes"<<endl;
        } else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}