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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main() {
	string a;
	int ans,i,j,p=0;
	stack<int> s;
	while (1) {
		ans = 0;
		i = 0;
		while (s.size()!=0) {
			s.pop();
		}
		getline(cin, a);
		F(j,100) {
			if (i == 0 && a[j] == '.') {
				p = 1;
				break;
			}
			if (a[j] == '.') {
				if (s.size()!=0 ){
					ans = 1;
					break;
				}
				break;
			}
			if (a[j] == '(')s.push(1);
			if (a[j] == '[')s.push(2);
			if (a[j] == ')') {
				if (s.size() == 0) {
					ans = 1;
					break;
				}
				if (s.top() == 1) {
					s.pop();
				}
				else {
					ans = 1;
				}
			}
			if (a[j] == ']') {
				if (s.size() == 0) {
					ans = 1;
					break;
				}
				if (s.top() == 2) {
					s.pop();
				}
				else {
					ans = 1;
					break;
				}
			}
			i = 1;

		}
		if (p == 1)break;
		if (ans == 0)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main(){
	stack<int>st;
	string s;
	while(1){
		getline(cin,s);
		if(s==".") return 0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='(') st.push(0);
			if(s[i]=='[') st.push(1);
			if(s[i]==')'){
				if(st.empty()){
					cout<<"no"<<endl;
					return 0;
				}
				int num=st.top();
				if(num==0){
					st.pop();
				}
				else{
					cout<<"no"<<endl;
					return 0;
				}
			}
			if(s[i]==']'){
				if(st.empty()){
					cout<<"no"<<endl;
					return 0;
				}
				int num=st.top();
				if(num==1){
					st.pop();
				}
				else{
					cout<<"no"<<endl;
					return 0;
				}
			}
		}
		if(st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

char pop(stack<char>& st) {
	char c = st.top();
	st.pop();
	return c;
}

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

C++: #include<iostream>
#include<stdio.h>
#include<string>
#include<stack>
using namespace std;
int brkat(string s){
  stack<int> st;
  int i;
  st.push(111);
  for(i=0;s[i]!=0;i++){
    if(s[i]=='[')       st.push(s[i]);	  
    if(s[i]=='(')       st.push(s[i]);
    if(s[i]==']')      
      {
      if('['!=st.top() )
	{  cout <<"no\n"; return 2;}
      st.pop();}	
  
    if(s[i]==')')  
      {
	if('('!=st.top() )
	  {cout <<"no\n"; return 2;}
	st.pop();}
    //    cout <<i<<"ggg\n";
  }
  if(st.top()!=111){
    cout <<"no\n"; return 2;}
  cout <<"yes\n"; return 0; 
  
}

int main(){
  stack<int> st;
  string s;
  //int ouput[10000];
  int i,j=0;

  while(1){
    i=0;
    getline(cin,s);
        if (s==".") break;
	  brkat(s);
    j++;
  }
  /*  for(i=0;i<j;i++){
    if (ouput[i]==2) cout <<"no\n";
    if (ouput[i]==0) cout <<"yes\n";
  }
  */
  return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;

string removeExceptParens(string);
bool isBalancedParens(string);

int main() {
	vector<string> lines;
	while (true) {
		string line = "";
		getline(cin, line);
		if (line == ".") {
			break;
		}
		lines.push_back(line);
	}

	for (vector<string>::iterator it = lines.begin(); it != lines.end(); it++) {
		string parenRemovedLine = removeExceptParens(*it);
		if (isBalancedParens(parenRemovedLine)) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}

string removeExceptParens(string str){
	string result = "";	
	for (string::iterator it = str.begin(); it != str.end(); it++) {
		if (*it == '(' || *it == ')' || *it == '[' || *it == ']') {
			result += *it;
		}
	}
	return result;
}

bool isBalancedParens(string str) {
	cout << str << endl;
	if (str == "") {
		return true;
	}
	else {
		string::size_type paren1 = str.rfind("()");
		string::size_type paren2 = str.rfind("[]");
		if (paren1 == string::npos && paren2 == string::npos) {
			return false;
		}
		else {
			if (paren1 != string::npos) {
				str.replace((int)paren1, 2, "");
			}
			else if (paren2 != string::npos) {
				str.replace((int)paren2, 2, "");
			}
			return isBalancedParens(str);
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		int a[100][100]={0},k1=0,k2=0,b=0,c1=0,c2=0,c3=0,c4=0;
		a[50][50]=1;
		for(int i=0;i<s.size();i++){
			if(s[i]=='('){
				k1++;
				a[50+k1][50+k2]++;
				c1++;
			}
			else if(s[i]==')'){
				a[50+k1][50+k2]=0;
				k1--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
				c2++;
			}
			else if(s[i]=='['){
				k2++;
				a[50+k1][50+k2]++;
				c3++;
			}
			else if(s[i]==']'){
				a[50+k1][50+k2]=0;
				k2--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
				c4++;
			}
		}
		if(b==0&&c1==c2&&c3==c4){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}
    return 0;
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main() {
	string s;
	while (getline(cin, s)) {
		if (s == ".")return 0;
		bool b = true;
		stack<char>l;
		for (int i = 0; i != s.size(); i++) {
			if (s[i] == '(' || s[i] == '[') {
				l.push(s[i]);
			}
			else if (s[i] == ')') {
				if (l.size() == 0)b = false;
				else if (l.top() == '(') {
					l.pop();
				}
				else b = false;
			}
			else if (s[i] == ']') {
				if (l.size() == 0)b = false;
				else if (l.top() == '[') {
					l.pop();
				}
			}
		}
		if (l.size() != 0)b = false;
		if (b)cout << "yes\n";
		else cout << "no\n";
	}
}