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 <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
	while(getline(cin,s)&&s!="."){
		vector<int> vi;
		bool ok=true;
		rep(i,s.size()){
			if(!ok)continue;
			if(s[i]=='['){
				vi.push_back(0);
			}
			else if(s[i]=='('){
				vi.push_back(1);
			}
			else if(s[i]==']'){
				if(vi.size()==0)ok=false;
				else if(vi.back()!=0)ok=false;
				else vi.pop_back();
			}
			else if(s[i]==')'){
				if(vi.size()==0)ok=false;
				else if(vi.back()!=1)ok=false;
				else vi.pop_back();
			}
		}
		if(vi.size()!=0)ok=false;
		if(ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<stack>
#include <cmath>
using namespace std;
bool paren(char a,char b){
	return (a=='('&&b==')')||(a=='['&&b==']');
}
int main(){
	string str;
	while(getline(cin,str)&&str!="."){
		int flg=1;
		stack<char> stk;
		for(unsigned i=0;i<str.size()&&flg==1;i++){
			switch(str[i]){
			case '(':
			case '[':
				stk.push(str[i]);
				break;
			case ']':
			case ')':
				if(stk.empty()||!paren(stk.top(),str[i])){
					flg=0;
				}
				if(flg)stk.pop();
			}
		}
		cout<<(flg==1?"yes":"no")<<endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    string s; getline(cin, s);
    if(s == ".") break;
    stack<char> st;
    bool balance = true;
    REP(i, SZ(s)) {
      if(s[i] == '(' || s[i] == '[') st.push(s[i]);
      else if(s[i] == ')') {
        if(!st.empty() && st.top() == '(') st.pop();
        else balance = false;
      } else if(s[i] == ']') {
        if(!st.empty() && st.top() == '[') st.pop();
        else balance = false;
      }
    }
    if(balance && st.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include<iostream>
#include<string>

int main(){
	while(1){
		std::string str;
		char bef;
		int count=0;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				count++;
				bef=str[i];
			}else if(str[i]==')'||str[i]==']'){
				count--;
				if(!((str[i]==')'&&bef=='(')||(str[i]==']'&&bef=='['))){
					std::cout<<"no"<<std::endl;
					goto end;
				}
			}
		}
		if(count==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

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

#define MAX_STR_LEN 102

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);
//		puts(inputStr);
		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) - 1] = '\0';
		(*bracketStrIdx)--;
	}
	else
	{
		return 1;
	}
	
	return 0;
}