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;

int main(){
    ios::sync_with_stdio(false);
    while(1){
        string s; getline(cin,s);
        if(s[0] == '.') break;

        stack<char>data;
        bool flag = true;
        for(int i=0; i<s.size(); i++){
            if(s[i] == '(' || s[i] == '[') data.push(s[i]);
            if(s[i] == ')' || s[i] == ']'){
                if(data.empty()){
                    flag = false;
                    break;
                }
                if((data.top() == '(' && s[i] == ']')
                ||  (data.top() == '[' && s[i] == ')')){
                    flag = false;
                    break;
                }
                data.pop();
            }
        }
        if(flag && data.empty()) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

int main(){
    for(;;){
        char S[110];
        gets(S);
        if(S[0]=='.')break;
        int m=0,k=0;
        int n = strlen(S);
        stack<int> h;
        h.push(0);
        for (int i=0; i<n; i++) {
            if(S[i]=='('){
                m++;
                h.push(1);
            }
            if(S[i]==')'){
                if(h.top()==2 or h.top()==0){
                    m=-1;
                    break;
                }
                h.pop();
                m--;
            }
            if(S[i]=='['){
                k++;
                h.push(2);
            }
            if(S[i]==']'){
                if (h.top()==1 or h.top()==0){
                    k=-1;
                    break;
                }
                h.pop();
                k--;
            }
            if (m<0 or k<0) {
                break;
            }
        }
        if(m==0 and k==0){
            cout <<"yes"<<endl;
        }else{
            cout << "no"<<endl;
        }
    }
}

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

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

using namespace std;

int main() {
  while(1){
    stack<char> s;
    string str;
    getline(cin, str);
    if (str == ".") break;
    bool valid = true;
    for(char c : str) {
      switch(c){
       case '(':
       case '[':
        s.push(c);
        break;
       case ')':
        if(s.empty() || s.top() != '('){
          valid = false;
        }else{
          s.pop();
        }
        break;
       case ']':
        if(s.empty() || s.top() != '['){
          valid = false;
        }else{
          s.pop();
        }
        break;
      }
    }
    if(valid && s.empty())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <cassert>
// using namespace std;
// #define int long long
#define REP(i,s,n) for (int i = (s); i < (n); ++i)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) for (int i = n; i >= 0; i--)
#define INF (int)(1e9+7)
#define space " "
#define ENDL "\n"
#define MAXL 100

int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};

inline void init() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
}
// ??¢?????¬??????????????????????????????????????????!!
inline void nextInt(int *a) { scanf("%d", a); }
inline void nextInt(int *a, int *b) { scanf("%d %d", a, b); }
inline void nextInt(int *a, int *b, int *c) { scanf("%d %d %d", a, b, c); }
inline void nextDouble(double *a) { scanf("%lf", a); }
inline void nextDouble(double *a, double *b) { scanf("%lf %lf", a, b); }
inline void nextDouble(double *a, double *b, double *c) { scanf("%lf %lf %lf", a, b, c); }
inline void nextLine(char *c) { scanf("%s", c); getchar();/*?????????????????¨???*/ }
inline std::string nextLine() {
    std::string s = ""; char str[MAXL+1];
    scanf("%s", str); getchar(); /*?????????????????¨???*/
    return s += str;
}
inline void print(double *a, int n = 0) {
    std::cout << std::fixed << std::setprecision(n) << *a << ENDL;
}
inline void print(int a) {
    printf("%d\n", a);
}

/************************End of templete*************************/

int main() {
    std::string s;
    bool flag = true;
    std::stack<char> st, ini;

    init();

    while (true) {
        st = ini;
        flag = true;
        std::getline(std::cin, s);
        if (s[0] == '.') break;

        rep(i,s.size()) {
            if (s[i] == '(' || s[i] == '[') {
                st.push(s[i]);
            } else if (s[i] == ')') {
                if (st.empty()) {
                    flag = false;
                    break;
                } else if (st.top() == '(') {
                    st.pop();
                } else {
                    flag = false;
                    break;
                }
            } else if (s[i] == ']') {
                if (st.empty()) {
                    flag = false;
                    break;
                } else if (st.top() == '[') {
                    st.pop();
                } else {
                    flag = false;
                    break;
                }
            }
        }

        if (flag) std::cout << "yes" << ENDL;
        else std::cout << "no" << ENDL;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int ro,so,i,j,k,b[51]={},p=0;
  while(str.size()!=1||str[0]!='.'){
    ro=0;so=0;k=0;p=0;
    for(i=0;i<str.size();i++){
      if(str[i]=='(') {
	ro++;
	p++;
	b[p]=0;
      }
      if(str[i]=='[') {
	so++;
	p++;
	b[p]=1;
      }	  
      if(str[i]==')') {
	if(b[p]==0) {
	  ro--;
	  p--;
	}
	else k=1;
      }
      if(str[i]==']') {
	if(b[p]==1) {
	  so--;
	  p--;
	}
	else k=1;
      }

      if(ro<0||so<0) k=1;
    }
    if(k==0&&ro==0&&so==0) cout << "yes" << endl;
    else cout << "no" << endl;
    getline(cin,str);
  }
  return 0;
}