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 <bits/stdc++.h>
using namespace std;

string S;

bool check(){
    stack<char> s;
    for (int i=0;i<S.size();++i){
        if (S[i]=='(') s.emplace('(');
        if (S[i]=='[') s.emplace('[');
        if (S[i]==')'){
            if (s.empty()||s.top()!='(') return false;
            s.pop();
        }
        if (S[i]==']'){
            if (s.empty()||s.top()!='[') return false;
            s.pop();
        }
    }
    return s.empty();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(getline(cin,S),S!="."){
        stack<char> s;
        cout << (check()?"yes":"no") << '\n';
    }
}

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

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 <bits/stdc++.h>
#include <stdio.h>
using namespace std;

string str;

bool input(){
		getline(cin,str);
		return str != ".";
}

void solve(){
//	cout << str <<endl;
	int maru=0;
	int kaku=0;
	char flag;
	int count = 0;
	char lst[101];
	for(int i = 0; i < (int)str.size();i++){
			char c =str[i];
			if(c == '('){
					maru++;
					lst[count]='(';
					count++;
					//flag = ')';
			}
			if(c == '['){
					kaku++;
					lst[count] = '[';
					count++;
					//flag = ']';
			}
			if(c == ')'){
					if(maru <= 0 || lst[count-1] !='('){
							cout << "no"  << endl;
							return;
					}
					
					maru --;
					count--;
			}
			if(c == ']'){
					if(kaku <= 0 || lst[count-1] != '['){
							cout << "no" << endl;//c << endl;
							return;
					}
					kaku--;
					count--;
			}
	}
	if(maru == 0 && kaku == 0)cout << "yes" <<endl;
	else cout << "no" <<endl;
}

int main(){
		while(input())solve();
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    string s;
    while(getline(cin,s)){
        if(s.size()==1&&s[0]=='.') break;
        stack<char>st;
        bool check=true;
        rep(i,s.size()){
            if(s[i] =='(' || s[i] == '[')
                st.push(s[i]);
            else if(s[i]==')'){
                if(st.empty()) check=false;
                else if(st.top()=='(') st.pop();
                else check=false;
            }else if(s[i]==']'){
                if(st.empty())check=false;
                else if(st.top()=='[')st.pop();
                else check=false;
            }
            if(!check) break;
        }
        if(st.empty() &&check) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}