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>

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		if(str == ".")
		{
			break;
		}
		int parentheses = 0;
		int box_brackets = 0;
		bool ok_flag = true;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == '(')
			{
				++parentheses;
			}
			else if(str[i] == '[')
			{
				++box_brackets;
			}
			else if(str[i] == ')')
			{
				--parentheses;
				if(parentheses < 0)
				{
					cout << "no" << endl;
					ok_flag = false;
					break;
				}
			}
			else if(str[i] == ']')
			{
				--box_brackets;
				if(box_brackets < 0)
				{
					cout << "no" << endl;
					ok_flag = false;
					break;
				}
			}
		}
		if(ok_flag)
		{
			cout << "yes" << endl;
		}
	}
}

int main()
{
	solve();
	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;
		}
	}

	// debug
	string end;
	cin >> end;
	// debug

	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) {
	if (str == "") {
		return true;
	}
	else {
		string::size_type paren1 = str.find("()");
		string::size_type paren2 = str.find("[]");
		if (paren1 == string::npos && paren2 == string::npos) {
			return false;
		}
		else {
			if (paren1 != string::npos) {
				str.replace((int)paren1, 2, "");
			}
			if (paren2 != string::npos) {
				str.replace((int)paren2, 2, "");
			}
			return isBalancedParens(str);
		}
	}
}

C++: #include <stdio.h>
#include <string.h>

#define MAX_STR_LEN 100

int CheckBracket(char *bracketStr, int *bracketStrIdx, char inputStr);

int main()
{
	char inputStr[MAX_STR_LEN]   = {'\0'};		// Array for input string
	int  inputStrLen = 0;						// Length of input string
	char bracketStr[MAX_STR_LEN] = {'\0'};		// Array for keep left-bracket
	int  bracketStrIdx = 0;						// Index of "bracketStr"
	char compareBracket = '\0';					// Valiable of select bracket to compare
	int  falseFlg = 0;							// Flag of sign false
	int  i = 0;									// Loop valiable
	
	do{
		// Initialize parameter.
		for(i = 0; i < MAX_STR_LEN; i++)
		{
			inputStr[i]    = '\0';
			bracketStr[i]  = '\0';
		}
		bracketStrIdx  = 0;
		compareBracket = '\0';
		falseFlg       = 0;
		
		// Input string.
		printf("Input string >> ");
		fgets(inputStr, MAX_STR_LEN, stdin);
		inputStrLen = strlen(inputStr);
		
		// If input string is '.' only, end.
		if('.' == inputStr[0])
		{
			break;
		}
		
		// Check to match bracket.
		for(i = 0; i < inputStrLen; i++)
		{
			switch(inputStr[i])
			{
			// If inputStr[i] is left-bracket, connect to "bracketStr".
			case '(':
			case '[':
				bracketStr[bracketStrIdx] = inputStr[i];
				bracketStrIdx++;
				break;
				
			// If inputStr[i] is right-bracket, Check to match bracket.
			case ')':
			case ']':
				falseFlg = CheckBracket(bracketStr, &bracketStrIdx, inputStr[i]);
				break;
				
			case '.':
				// If bracketStr is not empty, falseFlg is 1.
				if(0 != bracketStrIdx)
				{
					falseFlg = 1;
				}
				break;
			default:
				break;
			}
			
			if(1 == falseFlg)
			{
				break;
			}
		}
		
		// Disp result.
		if(0 == falseFlg)
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}while(1);
	
	return 0;
}

// CheckBracket
// Function  : Check to match bracket.
// Param[in] : char *bracketStr, int *bracketStrIdx, char inputStr
// Param[out]: 0(true) or 1(false)
// Global    : 
int CheckBracket(char *bracketStr, int *bracketStrIdx, char inputStr)
{
	char compareBracket = '\0';
	
	// If left-bracket is empty, falseFlg is 1.
	if(0 == *bracketStrIdx)
	{
		return 1;
	}
	
	// Select the compare bracket.
	if(')' == inputStr)
	{
		compareBracket = '(';
	}
	else
	{
		compareBracket = '[';
	}
	
	// Check to match bracket.
	if(compareBracket == bracketStr[*bracketStrIdx - 1])
	{
		bracketStr[*bracketStrIdx] = '\0';
		(*bracketStrIdx)--;
	}
	else
	{
		return 1;
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
bool saiki(string a,int& i){
  bool hantei=true;
  //cout<<a[i]<<endl;
  int j;
  for(j=i+1;j<a.size();j++){
    if((a[i]=='['&&a[j]==')')||(a[i]=='('&&a[j]==']'))return false;
    if(a[i]=='('&&a[j]==')'){
      i=j;
      return true;
    }
    if(a[i]=='['&&a[j]==']'){
      i=j;
      return true;
    }
    if(a[j]=='('||a[j]=='['){
      hantei=saiki(a,j);
      if(hantei==false)return false;
    }
  }
  return false;
}
int main(){
  string a;
  while(getline(cin,a),a.size()!=1&&a[0]!='.'){
    bool hantei = true;
    for(int i=0;i<a.size();i++){
      if(a[i]==')'||a[i]==']'){hantei=false;break;}
      if(a[i]=='('||a[i]=='['){
	hantei=saiki(a,i);
      }
      if(hantei==false){
	break;
      }
    }
    if(hantei==false)
      cout<<"no"<<endl;
    else
      cout<<"yes"<<endl;
  }
}

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

using namespace std;

void solve()
{
	string s;
	while (getline(cin, s))
	{
		if (s == ".")
		{
			return;
		}
		bool isBalanced = true;
		stack<char> Stack;
		for (int i = 0; i < s.size(); ++i)
		{
			if (s[i] == '(')
			{
				Stack.push('(');
			}
			else if (s[i] == '[')
			{
				Stack.push('[');
			}
			else if (s[i] == ')')
			{
				if (Stack.empty())
				{
					isBalanced = false;
					break;
				}
				char c = Stack.top();
				Stack.pop();
				if (c != '(')
				{
					isBalanced = false;
					break;
				}
			}
			else if (s[i] == ']')
			{
				if (Stack.empty())
				{
					isBalanced = false;
					break;
				}
				char c = Stack.top();
				Stack.pop();
				if (c != '[')
				{
					isBalanced = false;
					break;
				}
			}
		}
		if (isBalanced)
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}