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[100][101];
	int i=0;
	while(true){
		cin.getline(Input[i], sizeof(Input[i]));
		if(Input[i][0] == '.') break;
		i++;
	}
	for(int j=0; j<i; j++){
		if(isYes(Input[j])){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	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<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    string inp;
    while(getline(cin, inp)){
        if(inp.size() == 1 && inp[0] == '.') break;
        string str;
        rep(i,inp.size()){
            if(inp[i] == '(' || inp[i] == ')' || inp[i] == '[' || inp[i] == ']'){
                str+=inp[i];
            }
        }
        while(str.size()){
            string copy = str;
            rep(i,str.size() - 1){
                if((str[i] == '(' && str[i + 1] == ')') || (str[i] == '[' && str[i + 1] == ']')){ 
                    str.erase(i,2);
                    break;
                }
            }
            if(copy == str) break;
        }
        if(str.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

C++: #include <stdio.h>



int main(void){
  char c, moji[101];
  int maru, kaku;
  while(1){ 
    maru = 0;
    kaku = 0;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	moji[i] = '\0';
	break;
      }else{
	moji[i] = c;
      }
    }
    if(moji[0] == '.'){
      break;
    }
    for(int i=0; i<101; i++){
      if(moji[i] == '\0'){
	break;
      }else if(moji[i] == '('){
	maru++;
      }else if(moji[i] == ')'){
	maru--;
	if(maru<0){
	  break;
	}
      }else if(moji[i] == '['){
	kaku++;
      }else if(moji[i] == ']'){
	kaku--;
	if(kaku<0){
	  break;
	}
      }
    }
    if(maru == 0 && kaku == 0){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}

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

#define TEST 0
#if TEST
FILE* in = freopen("./Q.txt", "r", stdin);
FILE* out = freopen("./A.txt", "w", stdout);
#endif


char s[3] = "([";
char e[3] = ")]";

int main(int argc, const char * argv[]) {
    while(1){
        string line; getline(cin, line);
        if(line == ".") break;
        //cin.ignore();
        
        bool ok = true;
        stack<char> brackets;
        for(int i = 0; i < line.size(); i++){
            for(int j = 0; j < 2; j++){
                if (line[i] == s[j]) {
                    brackets.push(line[i]);
                } else if (line[i] == e[j]){
                    if(brackets.empty()){
                        ok = false;
                    } else {
                        ok = (brackets.top() == s[j]);
                        brackets.pop();
                    }
                }
            }
            if(!ok) break;
        }
        ok &= brackets.empty();
        cout << (ok ? "yes" : "no") << endl;
    }
#if TEST
    fclose(in);
    fclose(out);
#endif
}

C++: #include<iostream>
#include<string>
#include<stack>
// #include<string.h>

using namespace std;

int main(){
	
	
	while(1){
		
		int  i ,a=0;
		
		string str;
		stack<char> strstack;
		
		getline(cin , str);
		
		if(str[0] == '.') return 0;
		
		for(i=0 ; i<100  ; i++){
			
// 		cout << str[i] << endl;
			
			if (str[i] == '.') break;
			
			else if (str[i] == '['){
				
//				printf("[の読み込み\n");
					
				strstack.push(str[i]);
				
			}
					
			else if (str[i] == '('){
				
//				printf("(の読み込み\n");
				strstack.push(str[i]);
				
			}
			
			else if (str[i] == ']'){
//				printf("]の読み込み\n");
				if( strstack.empty() ) {
					a = 1;
					break;
					
				}
				else {
					
					if(strstack.top() == '['){
						strstack.pop();
					}
					else {
						a = 1;
						break;
					}
				}
			
			}
			
			else if (str[i] == ')'){
//				printf(")の読み込み\n");
				if( strstack.empty() ){
					a = 1;
					 break;
				}
				else {
					
					if(strstack.top() == '('){
						strstack.pop();
					}
					else {
						a = 1;
						break;
					}
				}
			
			}
	
		}
		

		
		if(a==0 && strstack.empty() == 1)  {
			
			printf("yes\n");
			
		}
		else printf("no\n");
			 
	}
	
	
	return 0;
			
	
	

	
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int search(vector<char> &v, char c){
    for(int i = v.size() - 1; i >= 0; i--){
        if(v[i] == c){
            int a = 0, b = 0;
            FOR(j, i + 1, v.size()){
                if(v[j] == '(') a++;
                else if(v[j] == '[') b++;
                else if(v[j] == ')'){
                    if(a <= 0) return -1;
                    else a--;
                }
                else if(v[j] == ']'){
                    if(b <= 0) return -1;
                    else b--;
                }
            }
            if(a == 0 && b == 0) return i;
            else return -1;
        }
    }
    return -1;
}

int main(){
    string str;
    while(getline(cin, str)){
        if(str == ".") break;
        bool OKflg = true;
        vector<char> v;
        REP(i, str.length()){
            if(str[i] == '(') v.push_back('(');
            else if(str[i] == '[') v.push_back('[');
            else if(str[i] == ')'){
                int tmp = search(v, '(');
                if(tmp == -1){
                    OKflg = false;
                    break;
                } else REP(j, v.size() - tmp + 1) v.pop_back();
            }
            else if(str[i] == ']'){
                int tmp = search(v, '[');
                if(tmp == -1){
                    OKflg = false;
                    break;
                } else REP(j, v.size() - tmp + 1) v.pop_back();
            }
        //debug
        //REP(i, (int)(v.size())) cout <<v[i] <<", "; cout <<endl;
        }
        if(OKflg && v.size() == 0) cout <<"yes" <<endl;
        else cout <<"no" <<endl;
    }
    return 0;
}