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>
#include<string>
#include<stack>
#include<map>
using namespace std;

map<char,char> m;
stack<char> st;	

void check(string str){
	for(int i=0;i<str.size();i++){
		if(
			str[i]=='(' ||
			str[i]=='[' 
		){
			st.push(str[i]);
		} else if(
			str[i]==')' ||
			str[i]==']' 
		){
			if(!st.empty()){
				if(m[st.top()]==str[i]){
					st.pop();
				}
			}
		}
	}
}

bool isPeriod(string str){
	for(int i=0;i<str.size();i++){
		if(str[i]=='.') return true;
	}
	return false;
}

int main(){
	m['(']=')';
	m['[']=']';
	m['{']='}';
	string str;
	while(1){
		getline(cin,str);
		if(!str.compare(".")) break;
		check(str);
		if(isPeriod(str)){
			if(st.empty()){
				cout << "yes" << endl;
			}else {
				cout << "no" << endl;
			}
			while(!st.empty()){
				st.pop();
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <stack>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    while(getline(cin, s), s != ".")
    {
        stack<char> st;
        bool ok = true;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == '(' or s[i] == '[') st.push(s[i]);
            else if(s[i] == ')')
            {
                if(st.empty() or st.top() != '(')
                {
                    ok = false;
                    break;
                }
                st.pop();
            }
            else if(s[i] == ']')
            {
                if(st.empty() or st.top() != '[')
                {
                    ok = false;
                    break;
                }
                st.pop();
            }
        }
        if(ok and st.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

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

int main() {
	string b;
	int i, c=0,d=0,end=0;
	while (1) {
		getline(cin,b);
		for (i = 0; i<b.size(); i++) {
				if (b[i] == '(') { c += 1; }
				if (b[i] == ')') { c -= 1; }
				if (b[i] == '[') { d += 1; }
				if (b[i] == ']') { d -= 1; }
				if (c < 0 || d < 0) { break; }
				if (b[i] == '.'&&end == 1) { end = 2; }
				if (b[i] == '.'&&end==0) {end = 1;}
		}

			if (c == 0 && d == 0) {cout << "yes"<<endl; }
			else { cout << "no"<<endl; }
			c = 0, d = 0;
			if (end == 2) { break; }
			end = 0;
	};
	return 0;
}

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

int main(void){
	char std[101];
	
	while(1){
		//入力
		gets(std);
		if(std[0]=='.')break;

		//計算
		stack<int> s;
		s.push(0);
		int flag=1;
		for(int i=0; std[i]!='.'; i++){
			if		(std[i]=='('){
				s.push(1);
			}else if(std[i]=='['){
				s.push(2);
			}else if(std[i]==')'){
				if(s.top()!=1){flag=0; break;}
				s.pop();
			}else if(std[i]==']'){
				if(s.top()!=2){flag=0; break;}
				s.pop();
			}
		}
		if(s.top()!=0){
			flag=0;
		}

		//出力
		if(flag)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	
	return 0;
}

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

int main(){
  char baff[128];
  while(true){
    baff[1] = '\0';
    bool ans = true;
    stack<int> kako;
    fgets(baff, sizeof(baff), stdin);
    if(baff[0] == '.'){
      break;
    }

    for(int i = 0; i < strlen(baff); i++){
      if(baff[i] == '('){
	kako.push(1);
      }
      if(baff[i] == '['){
	kako.push(2);
      }
      if(baff[i] == ')'){
	if(kako.empty() || kako.top() != 1){
	  ans = false;
	  break;
	}else{
	  kako.pop();
	}
      }
      if(baff[i] == ']'){
	if(kako.empty() || kako.top() != 2){
	  ans = false;
	  break;
	}
	else{
	  kako.pop();
	}
      }
    }

    if(ans){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
    
  }
  
  return 0;
}

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 (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;
  }
}