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 <bits/stdc++.h>
using namespace std;

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

C++: 

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
 
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,-1,1,-1,1};
 
 
int main() {
string s;
	while(getline(cin,s)){
		cout<<s<<endl;
		if(s==".") break;
	int ans=1;
	int l=s.length();
	stack<int> st; 
	for(int i=0;i<l;i++){
		if(s[i]=='(') st.push(1);
		else if(s[i]=='[') st.push(2);
		else if(s[i]==')'){
		if(st.empty()==true){
		ans=0;
		break;		
		}
		if (st.top()==1){
		st.pop();		
		}
		else{
		ans=0;
		break;
		}
		}

else if(s[i]==']'){
if(st.empty()==true){
		ans=0;
		break;		
		}
		if (st.top()==2){
		st.pop();		
		}
		else{
		ans=0;
		break;
		}
}
		}
	if(ans==1 && st.empty()==true) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}


	return 0;
 
   }

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, 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 <stack>
using namespace std;

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

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

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