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 <stdio.h>
#include <string.h>

#define MAX_STR_LEN 101

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

C++: #include <iostream>
#include <utility>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

const int INF = 1 << 28;

int main()
{
  for(;;) {
    string str;
    getline(cin, str);

    if(str == ".") {
      break;
    }

    stack<int> list;
    int pl = 0;
    int kl = 0;
    bool flag = true;
    for(char c : str) {
      switch (c) {
        case '(':
          ++pl;
          list.push(0);
          break;
        case '[':
          ++kl;
          list.push(1);
          break;
        case ')':
          flag &= pl > 0;
          if(flag) {
            flag &= list.top() == 0;
            list.pop();
          }
          --pl;
          break;
        case ']':
          flag &= kl > 0;
          if(flag) {
            flag &= list.top() == 1;
            list.pop();
          }
          --kl;
          break;
      }
    }
    flag &= pl == 0;
    flag &= kl == 0;

    cout << (flag ? "yes" : "no") << endl;
  }

  return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	string ans[] = {"yes", "no"};

	while(1) {
		int flg = 0;
		string s;
		getline(cin, s);
		if( s == "." ) break;
		int paren = 0;
		int brack = 0;
		vector<int> type;
		for(int i = 0; i < s.length(); i++) {
			char ch;
			ch = s.at(i);
			switch(ch) {
				case '(':
					type.push_back(1);
					paren ++;
					break;
				case ')':
					if(type.size() == 0) {
						flg = 1;
					} else {
						if(type.back() != 1) flg = 1;
						else type.pop_back();
					}
					paren --;
					break;
				case '[':
					type.push_back(2);
					brack ++;
					break;
				case ']':
					if(type.size() == 0) {
						flg = 1;
					} else {
						if(type.back() != 2) flg = 1;
						else type.pop_back();
					}
					brack --;
					break;
				default:
					break;
			}
			if( paren < 0 || brack < 0 ) flg = 1;
		}
		if(paren != 0 || brack != 0) flg = 1;
		cout << ans[flg] << endl;

	}

	
	//while(1){}
	return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	
	while(1){
		string str;
		getline(cin , str);
		stack<char> s;
		int cnt=0,cnt2=0,flag=1;
		
		if(str=="."){
			break;
		}

		string ss;

		for(int i=0;i<str.size();i++){
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				ss+=str[i];
		}

		for(int i=0;i<ss.size();i++){
			if(ss[i]=='(' || ss[i]=='['){
				s.push(ss[i]);
				cnt++;
			}

			if(ss[i]==')'){
				if(cnt==0){
					flag=0;
					break;
				}
				if(s.top()=='('){
					cnt2++;
					s.pop();
				}else{
					flag=0;
					break;
				}
			}

			if(ss[i]==']'){
				if(cnt==0){
					flag=0;
					break;
				}
				if(s.top()=='['){
					cnt2++;
					s.pop();
				}else{
					flag=0;
					break;
				}
			}
		}

		if(cnt==cnt2&&flag==1){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}	
	}
	return 0;
}