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

bool isYes(char input[]);

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

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

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    while(1){
        string in;
        getline(cin,in);
        if(in==".")break;
        string tt="";
        string ken="()[]";
        bool k=1;
        for(int i=0;i<in.length();i++){
            if(in[i]==ken[0]){
                tt+=ken[0];
            }
            if(in[i]==ken[2]){
                tt+=ken[2];
            }
            bool frg=0;
            if(in[i]==ken[1]){
                if(tt[tt.length()-1]!=ken[0]){
                    cout<<"no"<<endl;
                    frg=1;
                    k=0;
                    break;
                }else{
                    string ss=tt;
                    tt="";
                    for(int j=0;j<ss.length()-1;j++){
                        tt+=ss[j];
                    }
                    continue;
                }
            }
            if(in[i]==ken[3]){
                if(tt[tt.length()-1]!=ken[2]){
                    cout<<"no"<<endl;
                    k=0;
                    frg=1;
                    break;
                }else{
                    string ss=tt;
                    tt="";
                    for(int j=0;j<ss.length()-1;j++){
                        tt+=ss[j];
                    }
                    continue;
                }
            }
            if(frg==1)break;
        }
        if(tt==""&&k==1)cout<<"yes"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  string str;
  string tmp;
  while(getline(cin, str) && str != "."){
    int p = 0, q = 0;
    bool flag = 1;
    tmp = "";
    
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '[' || str[i] == '(' || str[i] == ']' || str[i] == ')'){
	tmp += str[i];
      }
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' && tmp[i+1] == ']') flag = 0;
      if(tmp[i] == '[' && tmp[i+1] == ')') flag = 0;
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      //printf("p = %d, q = %d\n", p, q);
      if(p < 0 || q < 0){
	flag = 0;
	break;
      }
      if(tmp[i] == '(') p++;
      if(tmp[i] == '[') q++;
      if(tmp[i] == ')') p--;
      if(tmp[i] == ']') q--;
    }
    if(p != 0 || q != 0) flag = 0;
    
    if(flag == 1) cout << "yes" << endl;
    else cout << "no" << endl;    
  }
  return 0;
}

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

int main(){
  char ch;
  while(1){
    stack<int> S1,S2;
    scanf("%c",&ch);
    if(ch=='.')break;
    int i=0;
    bool flag=0;
    while(1){
      if(i!=0)scanf("%c",&ch);
      if(ch=='.')break;
      
      if(ch=='[') S1.push(i);
      else if(!S2.empty()){
	if(ch==']'&&S1.size()>0&&S1.top()>S2.top()) S1.pop();
	else if(ch==']'&&S1.size()==0)flag=1;
      }else if(ch==']'&&S1.size()>0)S1.pop();
      else if(ch==']')flag=1;
      
      if(ch=='(')S2.push(i);
      else if(!S1.empty()){
	if(ch==')'&&S2.size()>0&&S2.top()>S1.top()) S2.pop();
	else if(ch==')'&&S2.size()==0)flag=1;
      }else if(ch==')'&&S2.size()>0) S2.pop();
      else if(ch==')')flag=1;
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
 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]==')' || str[pos]==']') return false;
    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();
      }
    }else if(Stack.empty() && (str[pos]==')' ||str[pos]==']')){
      return false;
    }
  }
  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;
}