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 <cstring>
#include <string>

using namespace std;

int main() {
  char buf[101];
  while (true) {
    fgets(buf, 101, stdin);
    if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
    if (buf[0] == '.' && buf[1] == '\0') break;
    string s = "";
    for (int i=0;buf[i]!='\0';i++) {
      if (buf[i] == '(' || buf[i] == ')'
        || buf[i] == '[' || buf[i] == ']') {
        s += buf[i];
      }
    }
    //printf("%s\n", s.c_str());
    bool yes = true;
    while (!s.empty()) {
      int n = s.find("()");
      if (n == string::npos) {
        n = s.find("[]");
        if (n == string::npos) {
          yes = false;
          break;
        }
      }
      s.erase(n, 2);
    }
    puts(yes ? "yes" : "no");
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[1000];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	  hoge[i] = getchar();
	  //	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else{
		  mini = 100;
		  break;
		}
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else{
		  big = 100;
		  break;
		}
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

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

using namespace std;
const static int STRLEN_MAX = 110;
enum KType{
  PAREN,
  BRACKET
};

bool analyse( string str ) {
  stack<KType> stk;
  int len = str.size();
  for( int i = 0; i < len; i++ ) {
    switch ( str[ i ] ) {
      case '(':
        stk.push( PAREN );
        break;
      case '[':
        stk.push( BRACKET );
        break;
      case ')':
        if( stk.empty() ) { return false; }
        if( stk.top() != PAREN ) { return false; }
        stk.pop();
        break;
      case ']':
        if( stk.empty() ) { return false; }
        if( stk.top() != BRACKET ) { return false; }
        stk.pop();
        break;
    }
  }
  return stk.empty();
};

int main() {
  char str[ STRLEN_MAX ];
  int pos = 0;
  while( 1 ) {
    int c = getchar();
    if( c == '\n' || c == '\r' ) { continue; }
    str[ pos++ ] = c;
    if( c == '.' ) {
      str[ pos ] = '\0';
      if( string( str ) == "." ) { return EXIT_SUCCESS; }
      cout << ( analyse( str ) ? "yes" : "no" ) << endl;
      pos = 0;
    }
  }
}

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

int main(){
	string str;
	while(1){
		getline(cin, str);
		if(str==".") break;
		stack<char> B;
		B.push(0);
		bool judge = false;

		for(int i=0;i<str.length();i++){
			if(str[i]=='(' | str[i]=='['){
				B.push(str[i]);
			} else if(str[i]==')'){
				if(B.empty() || B.top()!='(') break;
				else B.pop();
			} else if(str[i]==']'){
				if(B.empty() || B.top()!='[') break;
				else B.pop();
			}
			if(i==str.length()-1) judge = true;
		}
		cout<< ((judge) ? "yes" : "no" )<<endl;
	}

	return 0;
}

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






int main(){
  string s;
  while(getline(cin,s)){
    if(s=="."){break;}
  int k=0,m=0;
  int count=0;
  stack<int>  a;
  a.push(0);
  bool j=true;
  for(int i=0;i<s.size();i++){
    if(s[i]=='('){k++; a.push(1);}
    if(s[i]==')'){k--; if(a.top()!=1){j=false; break;} a.pop();}
    if(s[i]=='['){m++; a.push(2);}
    if(s[i]==']'){m--; if(a.top()!=2){j=false; break;} a.pop();}
  }
  if(k!=0 || m!=0){j=false;}
  if(j){cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
  
  }
  
  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		int a[100][100]={0},k1=0,k2=0,b=0,i=0;
		a[50][50]=1;
		while(s[i]!='.'){
			if(s[i]=='('){
				k1++;
				a[50+k1][50+k2]++;
			}
			else if(s[i]==')'){
				a[50+k1][50+k2]=0;
				k1--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
			}
			else if(s[i]=='['){
				k2++;
				a[50+k1][50+k2]++;
			}
			else if(s[i]==']'){
				a[50+k1][50+k2]=0;
				k2--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
			}
			i++;
		}
		if(b!=0){
			cout<<"no"<<endl;
		}
		else{
			cout<<"yes"<<endl;
		}
	}
    return 0;
}

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

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

  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  while(true){
    getline(cin,s);
    //cout << s << endl;
    if(s==".") break;
    int len=s.length();
    std::vector<char> v;
    for(int i=0;i<len;i++){
      if(s[i]=='(' || s[i]==')' || s[i]=='[' || s[i]==']'){
        v.push_back(s[i]);
      }
    }
    bool update=true;
    while(update){
      update=false;
      int le=v.size();
      for(int i=0;i<le-1;i++){
        if((v[i]=='(' && v[i+1]==')') || (v[i]=='[' && v[i+1]==']')){
          v.erase(v.begin()+i,v.begin()+i+2);
          update=true;
          i=le;
        }
      }
      //for(int i=0;i<v.size();i++) cout << v[i];
      //cout << endl;
    }
    if(v.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}