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 <stdio.h>
#include <stack>
#include <string>
using namespace std;

int main() {
	while (true) {
		char s[101];
		int c;
		int j = 0;
		while (true) {
			c = getchar();
			if (c == '\n') break;
			s[j++] = c;
		}
		s[j] = '\0';
		if (s[0] == '.') return 0;
		
		stack<char> stk;
		for (int i = 0; s[i] != '\0'; i++) {
			if (s[i] == '(') stk.push('(');
			else if (s[i] == '[') stk.push('[');
			else if (s[i] == ')') {
				if (!stk.empty()) {
					if (stk.top() == '(') stk.pop();
					else stk.push(')');
				} else stk.push(')');
			} else if (s[i] == ']') {
				if (!stk.empty()) {
					if (stk.top() == '[') stk.pop();
					else stk.push(']');
				} else stk.push(']');
			}
		}
		
		if (stk.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

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

char bl[5]= "([)]";

int main(){
    char str[101];
    while(1){
        cin.getline(str, 101);
        if(str[0]=='.') break;

        stack<char> seq;
        for(int i=0; str[i]!='.'; i++){
            for(int j=0; j<2; j++){
                if(str[i]==bl[j]){
                    seq.push(str[i]);
                }
            }
            for(int j=2; j<4; j++){
                if(str[i]==bl[j]){
                    if(seq.empty() || seq.top()!=bl[j-2]){
                        seq.push(0);
                        break;
                    }else{
                        seq.pop();
                    }
                }
            }
        }
        if(seq.empty()){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}

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

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

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

bool solve(string s) {
    stack<char> stk;
    rep(i, s.size()) {
        if(s[i] == '[') stk.push('[');
        if(s[i] == '(') stk.push('(');
        if(s[i] == ']') {
            if(stk.empty() or stk.top() != '[') return false;
            stk.pop();
        }
        if(s[i] == ')') {
            if(stk.empty() or stk.top() != '(') return false;
            stk.pop();
        }
    }
    return stk.empty();
}

int main()
{
    string s;
    while(getline(cin, s), s != ".") {
        if(solve(s)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

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

int main(){
  char ch;
  int f1=0,f2=0;

  while(1){
    stack<int> S1,S2;
    f1=f2=0;
    scanf("%c",&ch);
    int i=0;
    bool flag1=0,flag2=0;
    if(ch=='.')break;
    while(1){
      if(i!=0) cin>>ch;

      if(ch=='.') break;
      if(ch=='('){
	S1.push(i);
	if(f2==1) f1=2;
	else f1=1;
      }
  
  
      if(ch==')'&&S1.size()>0&&f2!=2){
	S1.pop();
	f1=0;
      }else if(ch==')')flag1=1;

      if(ch=='['){
	S2.push(i);
	if(f1==1)f2=2;
	else f2=1;
      }
      if(ch==']'&&S2.size()>0&&f1!=2){
	S2.pop();
	f2=0;
      }else if(ch==']')flag2=1;
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag1!=1&&flag2!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	string s;
	while(getline(cin,s)){
		if(s.length()==1)break;
		stack<char> st;
		st.push('#');
		bool flag = true;
		for(int i=0;i<s.length();i++){
			if(s[i]==')'){
				if(st.top()!='('){
					flag = false;
					break;
				}
				st.pop();
			}else if(s[i]==']'){
				if(st.top()!='['){
					flag = false;
					break;
				}
				st.pop();
			}else if(s[i]=='['||s[i]=='('){
				st.push(s[i]);
			}
		}
		if(st.top()!='#')flag=false;
		if(flag)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

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

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359

int main(void) {
  vector<string> ans;
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".")
      break;
    stack<int> st;
    bool flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(')
        st.push(1);
      else if (s[i] == '[')
        st.push(2);
      else if (s[i] == ')') {
        if (!st.empty() && st.top() == 1)
          st.pop();
        else {
          flag = false;
          break;
        }
      } else if (s[i] == ']') {
        if (!st.empty() && st.top() == 2)
          st.pop();
        else {
          flag = false;
          break;
        }
      }
      
    }
    if (flag) {
      ans.push_back("yes");
    } else {
      ans.push_back("no");
    }
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (true) {
        string s;
        getline(cin, s);
        // cout << "********************" + s << endl;
        if (s==".") break;

        stack<char> st;
        bool ok = true;
        for (const auto c: s) {
            if (c=='(' || c=='[') st.push(c);
            if (c==')') {
                if (!st.empty() && st.top()=='(') st.pop();
                else {ok = false; break;}
            }
            if (c==']') {
                if (!st.empty() && st.top()=='[') st.pop();
                else {ok = false; break;}
            }
        }
        if (!st.empty()) ok = false;

        if (ok) puts("yes");
        else puts("no");
    }
}