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<cstdio>
#include<iostream>
#include<stack>
using namespace std;

int main(){
  char ch;
  while(1){
    stack<int> S1,S2;
    scanf("%c",&ch);
    if(ch=='.')break;
    int i=0;
    bool flag=0;
    while(1){
      if(i!=0)scanf("%c",&ch);
      if(ch=='.')break;
      
      if(ch=='[') S1.push(i);
      else if(!S2.empty()){
	if(ch==']'&&S1.size()>0&&S1.top()>S2.top()) S1.pop();
      }else if(ch==']'&&S1.size()>0)S1.pop();
      else if(ch==']')flag=1;
      
      if(ch=='(')S2.push(i);
      else if(!S1.empty()){
	if(ch==')'&&S2.size()>0&&S2.top()>S1.top()) S2.pop();
      }else if(ch==')'&&S2.size()>0) S2.pop();
      else if(ch==')')flag=1;
      
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
 return 0;
}

C++: #include<iostream>

using namespace std;

int strin( string );
void brackets( string, int );

int main( void )
{
    int size;
    string str;
    while( 1 )
    {
        size = 0;
        str = "";
        getline( cin, str );
        size = strin( str );
        if( -1 == size )
        {
            break;
        }
        else
        {
            brackets( str, size );
        }
    }
    return 0;
}

int strin( string str )
{
    int count = 0;
    for( int loop = 0; loop < 100; loop++ )
    {
        if( ( '.' == str[loop] ) && ( 0 == loop ) )
        {
            return -1;
        }
        else if( '.' == str[loop] )
        {
            break;
        }
        count++;
    }
    return count;
}

void brackets( string str, int size )
{
    int Parenthese = 0;
    int brackets = 0;
    char input;
    for( int loop = 0; loop < size; loop++ )
    {
        switch( str[loop] )
        {
            case '(':
                Parenthese++;
                input = str[loop];
                break;
                
            case '[':
                brackets++;
                input = str[loop];
                break;
                
            case ')':
                Parenthese--;
                if( '[' == input )
                {
                    cout << "no" << endl;
                    return;
                }
                input = str[loop];
                break;
                
            case ']':
                brackets--;
                if( '(' == input )
                {
                    cout << "no" << endl;
                    return;
                }
                input = str[loop];
                break;
                
            default:
                break;
        }
        if( ( 0 > Parenthese ) || ( 0 > brackets ) )
        {
            cout << "no" << endl;
            return;
        }
    }
    if( ( 0 != Parenthese ) || ( 0 != brackets ) )
    {
        cout << "no" << endl;
        return;
    }
    else
    {
        cout << "yes" << endl;
    }
    
    return;
}

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

int main () {

  string input;

  while( true ) {

    getline( cin, input );

    if ( input == "." ) break;

    string s = " ";

    for ( long long int i = 0; i < input.size(); i++ ) {

      if ( input[i] == '(' ) {
	s += "(";
      }else if ( input[i] == '[' ) {
	s += "[";
      }else if ( input[i] == ')' ) {
	if ( s[ s.size() - 1 ] != '(' ) {
	  cout << "no" << endl;
	  break;
	}else {
	  s.erase( s.size() - 1 );
	}
      }else if ( input[i] == ']' ) {
	if ( s[ s.size() - 1 ] != '[' ) {
	  cout << "no" << endl;
	  break;
	}else {
	  s.erase( s.size() - 1 );
	}
      }

      if ( i == input.size() - 1 ) {
	if ( s == " " ) {
	  cout << "yes" << endl;
	}else {
	  cout << "no" << endl;
	}
      }

    }

  }

  return 0;

}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

string str;

bool solve(int p, char c) {
	for (int i = p+1; i < str.size(); i++) {
		if (str[i] == ']' || str[i] == ')') {
			if (str[i] == c) {
				str[p] = str[i] = ' ';
				return 1;
			} else {
				break;
			}
		} else if (str[i] == '(' || str[i] == '[') {
			char t = str[i] == '(' ? ')' : ']';
			if (!solve(i, t)) {
				break;
			}
		}
	}
	return 0;
}

int main()
{	
	while (getline(cin, str), str != ".") {
		bool f = 0;

		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(' || str[i] == '[') {
				f = 1;
				char t = str[i] == '(' ? ')' : ']';
				if (solve(i, t)) f = 0;
			}
			if (f) break;
		}
		if (!f) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

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

int main(){
  char ch;
  int f1=0,f2=0;
  
  while(1){
    stack<int> S1,S2;
    scanf("%c",&ch);
    int i=0;
    if(ch=='.')break;
    while(1){
      if(i!=0) cin>>ch;
      
      if(ch=='.') break;
      if(ch=='('){
	S1.push(i);
	if(f2==1) f1=2;
	else f1=1;
      }
      else if(ch==')'&&S1.size()>0&&f2!=2){
	S1.pop();
	f1=0;
      }else if(ch=='['){
	S2.push(i);
	if(f1==1)f2=2;
	else f2=1;
      }else if(ch==']'&&S2.size()>0&&f1!=2){
	S2.pop();
	f2=0;
      }
      i++;
    }
    if(S1.size()==0&&S2.size()==0) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	string str;
	
	while(1){
		stack <int> sta;
		int si = 0, f = 1;
		getline(cin, str);
		
		if(str == ".") break;
		
		si = str.size();
		
		for(int i = 0; i < si; i++){
			switch(str[i]){
				case '[': sta.push(1); break;
				case ']': if(sta.top() != 1)f = 0; sta.pop(); break;
				case '(': sta.push(2); break;
				case ')': if(sta.top() != 2)f = 0; sta.pop(); break;
			}
			if(f == 0) break;
		}
		
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		
	}
	return 0;
}

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

bool isYes(char input[]);

int main()
{
	char Input[100][101];
	int i=0;
	while(true){
		cin.getline(Input[i], sizeof(Input[i]));
		if(Input[i][0] == '.') break;
		i++;
	}
	for(int j=0; j<i; j++){
		if(isYes(Input[j])){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	enum __FLAG{NONE, PARE, BLAC};
	int prep[50], prepnum=0, p=NONE;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=PARE;
		} else if(Input[i] == '['){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=BLAC;
		} else if(Input[i] == ')'){
			if(p!=PARE){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=BLAC){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}