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<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
    string str;
    while(getline(cin,str),str!="."){
       vector<string>s(1000);
       int num=0;
       bool check=true;
       REP(i,str.size()){
           if(str[i]=='('){
              s[num]="(";
              num++;
           }
           if(str[i]=='['){
              s[num]="[";
              num++;
           }
           if(str[i]==')'){
              if(num==0){
                 check=false;
                 break;
              }
              if(s[num-1]!="("){
                 check=false;
                 break;
              }
              num--;
           }
           if(str[i]==']'){
              if(num==0){
                 check=false;
                 break;
              }
              if(s[num-1]!="["){
                 check=false;
                 break;
              }
              num--;
           }
       }
       if(check==true){
          cout<<"yes"<<endl;
       }else{
          cout<<"no"<<endl;
       }
    }
    return 0;
}

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

using namespace std;

int main() {
    while(true) {
LOOP:
        string s;
        getline(cin, s);
        const char* c = s.c_str();
        if(*c == '.') return 0;

        stack<char> st;

        for (char& ch : s) {
            if(ch == '[') {
                st.push('[');
                continue;
            } else if(ch == '('){
                st.push('(');
                continue;
            } else if(ch == ']') {
                if(st.empty()) {
                    cout << "no" << endl;
                    goto LOOP;
                }
                if(st.top() == '[') {
                    st.pop();
                    continue;
                }
                else {
                    cout << "no" << endl;
                    goto LOOP;
                }
            } else if(ch == ')') {
                if(st.empty()) {
                    cout << "no" << endl;
                    goto LOOP;
                }
                if(st.top() == '(') {
                    st.pop();
                    continue;
                } else {
                    cout << "no" << endl;
                    goto LOOP;
                }
            }
        }
        if(st.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

using namespace std;
typedef long long ll;

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

int main(void) {
  string s;
  char brackets[] = {'(', ')', '[', ']'};
  while (getline(cin, s) && s != ".") {
    stack<char> stk;
    bool yes = true;
    rep(i, s.size()) {
      bool is_bracket = false;
      rep(j, 4) if (s[i] == brackets[j]) is_bracket = true;
      if (!is_bracket)
        continue;
      if (stk.empty() || s[i] == '(' || s[i] == '[')
        stk.push(s[i]);
      else if ((stk.top() == '(' && s[i] == ')') ||
               (stk.top() == '[' && s[i] == ']'))
        stk.pop();
      else {
        yes = false;
        break;
      }
    }

    if (yes && stk.empty())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

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

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

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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

typedef std::pair<int, int> P;

int N;
std::string str;
int i;

bool solve(char prev) {
  for(;;) {
    while( str[i] != '(' and str[i] != ')' and str[i] != '[' and str[i] != ']' and i != N ) i += 1;
    if( i == N ) return (prev == '\0');
    
    if( str[i] == '(' ) {
      i += 1;
      if( not solve('(') ) return false;
      i += 1;
      continue;
    }
    if( str[i] == '[' ) {
      i += 1;
      if( not solve('[') ) return false;
      i += 1;
      continue;
    }
    if( prev == '(' and str[i] == ')' ) {
      return true;
    }
    if( prev == '[' and str[i] == ']' ) {
      return true;
    }
    return false;
  }
  return false;
}

int main() {

  for(;;) {
    std::getline(std::cin, str);
    if( str == "." ) break;
    N = str.size();
    i = 0;
    std::cout << (solve('\0') ? "yes" : "no") << std::endl;
  }
  
  return 0;
}

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

using namespace std;


int main(){
    string S;
    // getline(cin, S);
    while(getline(cin, S)){
        if(S[0] == '.') break;
        bool isNo = false;
        stack<char> brackets;
        for(int i = 0; i < S.size(); ++i){
            char tmp;
            if(S[i] == '.'){
                if(brackets.empty() == false){
                    // cout << "no1" << endl;
                    isNo = true;
                    break;
                }
            }else if(S[i] == '(' || S[i] == '['){
                brackets.push(S[i]);
            }else if(S[i] == ')'){
                if(brackets.empty() == false){
                    tmp = brackets.top();
                    brackets.pop();
                    if(tmp != '('){
                        isNo = true;
                        break;
                    }
                }else{
                    isNo = true;
                }
            }else if(S[i] == ']'){
                if(brackets.empty() == false){
                    tmp = brackets.top();
                    brackets.pop();
                    if(tmp != '['){
                        isNo = true;;
                        break;
                    }
                }else{
                    isNo = true;
                }
            }
        }
        if(isNo == false)
            cout << "yes" << endl;
        else    
            cout << "no" << endl;
    }
    return 0;
}