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 <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;
        }
      }
    }
    puts(ok?"yes":"no");
  }
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

const int MAX=100;

#define hoge(i,n) for(int i=0;i<n;i++)

int main(){
    while(true){
        int a=0,b=0;
        bool f = true;
        string s;
        getline(cin ,s);
        if(s[0]=='.'){break;}
        hoge(i, s.size()){
            if(s[i]=='('){a++;}
            if(s[i]==')'){a--;}
            if(s[i]=='['){b++;}
            if(s[i]==']'){b--;}
            if(a<0 || b<0){f=false; break;}
        }
        if(!(a==0&&b==0)){
            f=false;
        }

        if(f){
            cout << "yes"<<endl;
        }else{
            cout << "no"<<endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	string s;
	while(1){
		getline(cin, s);
		if(s == ".") break;
		stack<char> st;
		bool f = true;
		rep(i, 0, s.size()){
			if(s[i]=='(' || s[i]=='['){
				st.push(s[i]);
			}
			if(s[i]==')' || s[i]==']'){
				char tmp;
				if(st.empty()){
					f=false; break;
				}
				tmp = st.top(); st.pop();
				if((s[i]==')' && tmp=='[')||(s[i]==']' && tmp=='(')){
					f=false; break;
				}
			}
		}
		if(f && st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int search(int i, char c);

char str[200];
int l;

int main()
{
	while(1){
		fgets(str, sizeof(str), stdin);
		if(str[0] == '.') break;
		int ans = 1;
		l = strlen(str);
		for(int i = 0; i < l; i++){
			if(str[i] == '(' || str[i] == '['){
				ans = search(i, str[i]);
				if(ans == 0) break;
			} else if(str[i] == ')' || str[i] == ']'){
				ans = 0;
				break;
			}
		}
		if(ans == 1) cout << "yes" << endl;
		else if(ans == 0) cout << "no"<< endl;
	}
	return 0;
}

int search(int i, char c)
{
	if(i == l-2) return 0;
	char d, e;
	if(c == '('){
		d = ')';
		e = ']';
		}else if(c == '['){
			d = ']';
			e = ')';
		}
		str[i] = '0';
	for(int j = i+1; j < l; j++){
		if(str[j] == '(' || str[j] == '['){
			if(search(j, str[j]) == 0) return 0;
			else continue;
		} else if(str[j] == d){
			str[j] = '0';
			return 1;
		} else if(str[j] == e){
			str[j] = '0';
			return 0;
		}
	}
	return 0;
}

C++: #include <algorithm>
#include <stack>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

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

bool Check() {
    stack<char> s;
    for (string::iterator i = L.begin(); i != L.end(); i++) {
        switch (*i) {
            case '(': s.push(*i); break;
            case ')': 
                if (s.empty() || s.top() != '(') return false;
                s.pop();
                break;
            case '[': s.push(*i); break;
            case ']':
                if (s.empty() || s.top() != '[') return false;
                s.pop();
                break;
        }
    }
    return true;
}

void solve() {
    cout << (Check() ? "yes" : "no") << endl;
}

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

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

const int size = 101;
string line;
stack <char> S;

bool dfs( int i ) {
    if ( i == line.size() ) return true;
    if ( line[i] == '(' || line[i] == '[' ) {
        S.push( line[i] );
    } else if ( line[i] == ')' || line[i] == ']' ) {
        if ( S.empty() ) return false;
        if ( S.top() == '(' && line[i] == ']' ) return false;
        if ( S.top() == '[' && line[i] == ')' ) return false;
        S.pop();
    }
    return dfs( i+1 );
}

int main() {
    while ( getline( cin, line ) && line != "." ) {
        S = stack<char>();
        bool result = dfs( 0 );
        cout << ( result ? "yes" : "no" ) << endl;
    }
    return 0;
}

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

int main(){
  
  while(1){
    stack<char>op;
    string str;
    bool ff=true;
    
    getline(cin,str);
    if(str == ".") break;

    for(int i=0;str[i]!='.';i++){
      if(str[i] == '(')
	{
	  op.push('(');
	}
      else if(str[i] == ')')
	{
	  if( op.empty() || op.top() != '(' ){
	    ff = false;
	    break;
	  }
	  op.pop();
	}
      else if(str[i] == '[')
	{
	  op.push('[');
	}
      else if(str[i] == ']')
	{
	  if( op.empty() || op.top() != '['){
	    ff = false;
	    break;
	  }
	  op.pop();
	}
    }

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

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

int main() {
    while(true) {
        stack<char> cc;
        char c;
        bool success = true;
        string line;
        getline(cin, line);
        if(line == ".") break;
        for(int i = 0; i < line.size(); ++i) {
            c = line[i];
            if(c == '(') cc.push(')');
            if(c == '[') cc.push(']');
            if(c == ')') {
                if(!cc.empty() && cc.top() == ')') cc.pop();
                else success = false;
            }
            if(c == ']') {
                if(!cc.empty() && cc.top() == ']') cc.pop();
                else success = false;
            }
        }
        cout << ((success && cc.empty()) ? "yes" : "no") << endl;
    }
    return 0;
}