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>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char s[1000];
int main(){
	while(1) {
		fgets(s,500,stdin);
		int n = strlen(s);
		n--;
		if(n == 1 && s[0] == '.') {
			break;
		}


		stack<int> last;

		bool f = true;int rb = 0,sb = 0;
		REP(i,n) {
			if(!last.empty() && last.top() == 0 && s[i] == ']') {
				f = false;
				break;
			}
			if(!last.empty() && last.top() == 1 && s[i] == ')') {
				f = false;
				break;
			}
			if(s[i] == ')') {
				rb--;
				last.pop();
				if(rb < 0) {
					f = false;
					break;
				}
			}
			if(s[i] == ']') {
				sb--;
				last.pop();
				if(sb < 0) {
					f = false;
					break;
				}
			}
			if(s[i] == '(')  {
				rb++;
				last.push(0);
			}
			if(s[i] == '[')  {
				sb++;
				last.push(1);
			}
		}
		if(f) {
			cout << "yes" << endl;
		}else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

bool judge(string &str) {
  stack<char> s;
  char c;
  for(int i = 0; i < str.size(); ++i) {
    if(str[i] == '(' || str[i] == '[') {
      s.push(str[i]);
    } else if(str[i] == ')') {
      if(s.empty()) return false;
      c = s.top();
      s.pop();
      if(c != '(') return false;
    } else if(str[i] == ']') {
      if(s.empty()) return false;
      c = s.top();
      s.pop();
      if(c != '[') return false;
    }
  }
  return s.empty();
}

int main() {
  string str;
  while(getline(cin, str) && str != ".") {
    if(judge(str)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define MCLR(a) memset((a), -1 ,sizeof(a))
#define SZ(a) (sizeof(a))
#define FILL(a,v) fill((int*)a,(int*)(a+(SZ(a)/SZ(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){return x >= 0 && y >= 0 && xMax > x && yMax > y;}
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 10007;
const int INF = 2147483647;

int main()
{
	string s;

	while (getline(cin, s) && !(s[0] == '.' && s.size()==1)){
		int i;
		stack<char> sc;
		for(i = 0;i < s.size();i++){
			if (s[i] == '(' || s[i] == '[')sc.push(s[i]);

			if (s[i] == ')')if (sc.size() && sc.top() == '('){
				sc.pop();
			}
			else break;
			if (s[i] == ']')if (sc.size() && sc.top() == '['){
				sc.pop();
			}
			else break;
		}
		if (i == s.size() && !sc.size())cout << "yes" << endl;
		else							cout << "no"	<< endl;
	}

}

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

int main (){

	string a;
	bool IsOk = true; int LeftKakko = 0; int LeftKulo = 0; bool b = false;
	vector<int> v;
	while (cin >> a){
		if (a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				LeftKakko++;
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (LeftKakko == 0||v.back()!=1){
					IsOk = false;
				}
				else{
					LeftKakko--;
					v.pop_back();
				}
			}
			else if (a[i] == 91){//[
				LeftKulo++;
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (LeftKulo == 0||v.back()!=0){
					IsOk = false;
				}
				else{
					LeftKulo--;
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (LeftKakko != 0 || LeftKulo != 0||v.empty()==false){
					IsOk = false;
				}
				if (IsOk == true){
					cout << "yes"<<endl;
				}
				else{
					cout << "no"<<endl;
				}
				IsOk = true; LeftKakko = 0; LeftKulo = 0; v.clear();
			}
		}
	}
	return 0;
}

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

int main(void){
	string str;
	while(1){
		getline(cin, str);
		bool flg = true;
		if(str == ".") break;

		stack<char> q;
		for(int p=0; p < str.length(); p++){
			if(str[p] == '('){
				q.push('(');
			}
			if(str[p] == '['){
				q.push('[');
			}
			if(str[p] == ')'){
				if(q.empty() || q.top() != '('){
					flg = false;
					break;
				}else{
					q.pop();
				}
			}
			if(str[p] == ']'){
				if(q.empty() || q.top() != '['){
					flg = false;
					break;
				}else{
					q.pop();
				}
			}
		}
		if(q.empty() && flg) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main(){

    string s;


    while (1){
	bool b = true;
	
	getline(cin, s);
	if (s == ".") break;

	stack<char> st;
	
	for (int i = 0; i < s.size(); i++){
	    
	    switch (s[i]){
	    case '(': st.push('('); break;
	    case ')':
		if (st.empty() || st.top() != '(') b = false;
		else st.pop();
		break;
	    case '[': st.push('['); break;
	    case ']':
		if (st.empty() || st.top () != '[') b = false;
		else st.pop();
		break;
	    default: break;
	    }
	}

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

}

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

int main(){
    while(true){
        int cnt = 0;
        bool ju = true;
        string s;
        stack <char> box;
        getline(cin,s); if(s == ".") break;
        for(int i=0;i<s.size();i++){
            if(s[i] == '(' || s[i] == '['){
                box.push(s[i]); cnt++;
            }
            else if(s[i] == ')' || s[i] == ']'){
                if(!box.empty()){
                    if((s[i] == ')' && box.top() != '(') || (s[i] == ']' && box.top() != '[')){ ju = false; break; }
                    box.pop();
                }
                cnt--;
            }
            if(cnt < 0){
                ju = false; break;
            }
        }
        cout << ((ju)? "yes" : "no") << endl;
    }
}

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

bool solve(string &s) {
  stack<char> st;
  for(int i = 0; i < (int)s.length(); ++i) {
    if(s[i] == '[' || s[i] == '(') st.push(s[i]);
    if(s[i] == ']') {
      if (st.top() != '[') return 0;
      st.pop();
    }
    if(s[i] == ')') {
      if(st.top() != '(') return 0;
      st.pop();
    }
  }
  return 1;
}

int main() {
  string s;
  while(getline(cin, s) && s != ".") {
    cout << (solve(s) ? "yes" : "no") << endl;
  }
  return 0;
}