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>

using namespace std;

int main (){

	string a;
	bool IsOk = true; int LeftKakko = 0; int LeftKulo = 0; bool b = false;
	vector<int> v;
	while (cin >> a){
		if (a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				LeftKakko++;
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (LeftKakko == 0||v.back()!=1){
					IsOk = false;
				}
				else{
					LeftKakko--;
					v.pop_back();
				}
			}
			else if (a[i] == 91){//[
				LeftKulo++;
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (LeftKulo == 0||v.back()!=0){
					IsOk = false;
				}
				else{
					LeftKulo--;
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (LeftKakko != 0 || LeftKulo != 0){
					IsOk = false;
				}
				if (IsOk == true){
					cout << "yes"<<endl;
				}
				else{
					cout << "no"<<endl;
				}
				IsOk = true; LeftKakko = 0; LeftKulo = 0; v.clear();
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	string s;
	while (getline(cin, s)) {
		if (s == ".")break;
		bool f = true;
		int l = 0; int r = s.length()-1;
		while (r >= l) {
			if (s[l] == '(') {
				while (r >= l) {
					if (s[r] == '(') {
						f = false; break;
					}
					else if (s[r] == ')') {
						r--; break;
					}
					r--;
				}
				if (r < l)f = false;
			}
			else if (s[l] == '[') {
				while (r >= l) {
					if (s[r] == '[') {
						f = false; break;
					}
					else if (s[r] == ']') {
						r--; break;
					}
					r--;
				}
				if (r < l)f = false;
			}
			l++;
		}
		if (f)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);
//		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;
}

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

using namespace std;

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

}

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

C++: #include<iostream>
#include<cstring>
#include<vector>
using namespace std;

int main()
{

  for(;;)
    {
      char n[200];
      cin.getline(n,sizeof(n));
      if(n[0]=='.')
	break;
      bool check=true;
      int cnt1=0;
      int cnt2=0;
      string buf;
      int in=0;
      for(int i=0;n[i]!='.';i++)
	{
	  if(n[i]=='(')
	    {
	      cnt1++;
	      buf[in]=n[i];
	      in++;
	    }
	  if(n[i]=='[')
	    {
	      cnt2++;
	      buf[in]=n[i];
	      in++;
	    }
	  if(n[i]==')')
	    {
	      cnt1--;
	      in--;
	      if(in<0||buf[in]!='(')
		check=false;
	    }
	  if(n[i]==']')
	    {
	      cnt2--;
	      in--;
	      if(in<0||buf[in]!='[')
		check=false;
	    }
	  
	  if(cnt1<0||cnt2<0)
	    check=false;
	}

      if(cnt1!=0||cnt2!=0)
	check=false;
      
      if(check)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }
}

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

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