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++: #define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

int main(){
	string str;
	while(getline(cin,str)){
		if(str==".") break;
		stack<char> stk;
		string res = "yes";
		for(int i=0;i<str.size();i++){
			if(str[i]=='(') stk.push('(');
			if(str[i]=='[') stk.push('[');

			if(str[i]==')'){
				if(!stk.empty() && stk.top() != '(') res = "no";
				else if(stk.empty()) res = "no";
				else stk.pop();
			}

			if(str[i]==']'){
				if(!stk.empty() && stk.top() != '[') res = "no";
				else if(stk.empty()) res = "no";
				else stk.pop();
			}

		}

		if(!stk.empty()) res = "no";
		cout << res << endl;
	}
}

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

bool isYes(char input[]);

int main()
{
	char Input[101];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		if(Input[0] == '.') break;
		if(isYes(Input)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	enum __FLAG{NONE, PARE, BLAC};
	int prep[50], prepnum=0, p=NONE;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=PARE;
		} else if(Input[i] == '['){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=BLAC;
		} else if(Input[i] == ')'){
			if(p!=PARE){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=BLAC){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

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

using namespace std;

stack<char> stk;

char s[101];

int main(void){
	int i;
	
	while(1) {
		if(gets(s) == NULL) break;
		if(s[0] == '.' && s[1] == '\0') break;

		while(!stk.empty())
			stk.pop();
		int flag = 0;
		int l = strlen(s);
		int m = 0, k = 0;
		char past = '\0';

		for(i = 0; i < l && flag == 0; i++) {
			if( s[i] == '(' ) {
				stk.push('(');
			}
			if( s[i] == ')' ) {
				if(stk.empty()){
					flag=1;
					break;
				}
				if(stk.top() == '(') stk.pop();
				else flag = 1;
			}
			if( s[i] == '[' ) {
				stk.push('[');
			}
			if( s[i] == ']' ) {
				if(stk.empty()){
					flag=1;
					break;
				}
				if(stk.top() == '[') stk.pop();
				else flag = 1;
			}

		}

		if( !stk.empty() ) flag = 1;

		if( flag == 0 ) printf("yes\n");
		else printf("no\n");

	}

	return 0;
}

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

using namespace std;

int main(){
  bool flg=false,bflg;
int i;
  while(!flg){
    /*行ループ*/
    string s;
    stack<char> box;
    char ch;
    getline(cin,s);

    if(s==".")flg=true;
    else {
      /*区画ループ*/
      bflg=true;
      box.push('s');

      for(i=0;i<s.size();i++){
        ch=s.at(i);
        if(ch=='('||ch=='[')box.push(ch);
        else if(ch==')'){
          if(box.top()=='(')box.pop();
          else{
            bflg=false;
            break;
          }
        }
        else if(ch==']'){
          if(box.top()=='[')box.pop();
          else{
            bflg=false;
            break;
          }
        }
        else if(ch=='.'){
          break;
        }
      }
      if(bflg==true)cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	string str; while (getline(cin, str) && str[0] != '.' && str.size() != 1)
	{
		stack<int> stck;
		rep(i, (int)str.size())
		{
			switch (str[i])
			{
				case '(':	stck.push(1);	break;
				case '[': stck.push(2); break;
				case ')': 
					if (stck.size() == 0) {}
					else if (stck.top() == 1) { stck.pop(); }
					break;
				case ']': 
					if (stck.size() == 0) {}
					else if (stck.top() == 2) { stck.pop(); }
					break;
			}
		}
		if (stck.size() != 0) { printf("no\n"); }
		else { printf("yes\n"); }
	}
	return 0;
}

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

int main() {
    string str;

    while (true) {
        getline(cin, str);
        if (str == ".") break;

        int a=0, b=0;
        bool flag=true;
        rep(i, str.size()) {
            if (str[i] == '(') a++;
            else if (str[i] == ')') {
                if (a > 0) a--;
                else {
                    flag=false;
                    break;
                }
            }
            if (str[i] == '[') b++;
            else if (str[i] == ']') {
                if (b > 0) b--;
                else {
                    flag=false;
                    break;
                }
            }
        }
        cout << (flag ? "yes" : "no") << endl;
    }

}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<stack>

using namespace std;

#define INF 999999999

int main(){
	int i, j;
	char s[101];
	stack<int> st;
	int flag;
	
	while(1){
		gets(s);
		if(s[0]=='.')break;
		flag = 1;
		while(!st.empty()) st.pop();
		
		for(i=0;s[i]!='\0';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 = 0;
					break;
				}
			}
			else if(s[i]==']'){
				if(!st.empty()&&st.top()==2){
					st.pop();
				}
				else {
					flag = 0;
					break;
				}
			}
		}
		
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
typedef unsigned int uint;
using namespace std;

inline bool opp(char c1,char c2){
  return (c1==')' && c2 == ']') || (c1==']' && c2==')');
}

bool check(string str){
  stack<uint> Stack;
  uint pos=0;
  for(;pos<str.size();pos++){
    if(str[pos]=='('){
      Stack.push(')');
      break;
    }else if(str[pos]=='['){
      Stack.push(']');
      break;
    }
  }
  
  for(pos++;pos<str.size();pos++){
    if(str[pos]=='('){
      Stack.push(')');
    }else if(str[pos]=='['){
      Stack.push(']');
    }
    else if(!Stack.empty()){
      char c=Stack.top();
      if(opp(str[pos],c)){
	return false;
      }else if(str[pos]==c){
	Stack.pop();
      }
    }
  }
  if(Stack.empty())
    return true;  
  else 
    return false;
}

int main(){
  string str;
  while(getline(cin,str),str!="."){
    if(check(str))
      cout<<"yes"<<endl;
    else
      cout<<"no"<<endl;

  }
  return 0;
}