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 <cstdio>
#include <stack>
#include <string>
#include <vector>

using namespace std;

string s;
vector<bool> out;

int main(){
	do{
		s.clear();
		do{
			string temp;
			getline(cin,temp);
			s+=temp;
		}while(s[s.length()-1]!='.');
		if (s.length()!=1){
			stack<bool> st;	//(=0,[=1;
			int i=0,l=s.length();
			for (;i<l;i++){
				if (s[i]=='('){
					st.push(0);
				}
				else if (s[i]=='['){
					st.push(1);
				}
				else if (s[i]==')'){
					if (st.empty){
						out.push_back(false);
						break;
					}
					int type=st.top();
					st.pop();
					if (type!=0){
						out.push_back(false);
						break;
					}
				}
				else if (s[i]==']'){
					if (st.empty()){
						out.push_back(false);
						break;
					}
					int type=st.top();
					st.pop();
					if (type!=1){
						out.push_back(false);
						break;
					}
				}
			}
			if (i==l){
				if (st.empty()){
					out.push_back(true);
				}
				else{
					out.push_back(false);
				}
			}
		}
	}while(s.length()!=1);
	for (int i=0;i<out.size();i++){
		printf("%s\n",out[i] ? "yes" : "no");
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAX_N = 100 + 10;

char str[MAX_N];

int main()
{
    //freopen("in.txt", "r", stdin);
    while(gets(str) && str[0] != '.')
    {
        bool flag = false;
        stack <char> s;
        int len = strlen(str);
        int i;
        for(i = 0; i < len; i++)
        {
            if(str[i] == '.')
                break;
            if(str[i] == ']')
            {
                if(s.empty())
                {
                    printf("no\n");
                    flag = true;
                    break;
                }
                else
                {
                    if(s.top() == '[')
                        s.pop();
                    else
                    {
                        printf("no\n");
                        flag = true;
                        break;
                    }
                }
            }
            else if(str[i] == ')')
            {
                if(s.empty())
                {
                    printf("no\n");
                    flag = true;
                    break;
                }
                else
                {
                    if(s.top() == '(')
                        s.pop();
                    else
                    {
                        printf("no\n");
                        flag = true;
                        break;
                    }
                }
            }
            else if(str[i] == '(' || str[i] == '[')
                s.push(str[i]);
        }
        if(!flag)
            printf("yes\n");
    }
    return 0;
}

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

using namespace std;

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>

char st[10000];
bool ok;
int i, j, n, aa;
int a[1001];

int main() {
	gets(st);
	while (st[0] != '.') {
		n = strlen(st);
		for (i = 1; i <= n; ++i)
			if (st[i] == '[') {
				++aa;
				a[aa] = 1;
			}
			else if (st[i]==']') {
				++aa;
				a[aa]=2;
			}
			else if (st[i]=='(') {
				++aa;
				a[aa]=3;
			}
			else if (st[i]==')') {
				++aa;
				a[aa]=4;
			} 	 	 	
			ok = true;
			while (ok && (aa>0)) {
				ok=false;
				for (i=1;  i <= aa-1; ++i) if (((a[i]==1) && (a[i+1]==2)) || ((a[i]==3) && (a[i+1]==4))) {
					for (j=i; j <= aa-2; ++j) a[j]=a[j+2];
					a[aa]=0; a[aa-1]=0;
					aa-=2;
					ok=true;
					break;
				}
			}
		if (aa==0) printf("yes\n"); else printf("no\n");
		for (i=1 ; i <= aa; ++i) a[i]=0;
		aa=0;
		gets(st);
	}
 }

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

int main(void)
{
	string str;
	while (1){
		getline(cin, str);
		if (str[0] == '.' && str.length() == 1) break;

		stack <char> data;
		bool flag = true;
		data.push('*');
		for (int i = 0; i < (int)str.length(); i++){
			if (str[i] == '(' || str[i] == '[') data.push(str[i]);
			if (str[i] == ')'){
				if (data.top() == '(') data.pop();
				else flag = false;
			}
			if (str[i] == ']'){
				if (data.top() == '[') data.pop();
				else flag = false;
			}
		}
		if (data.top() == '*' && flag == true){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  string s;
  while( 1 ) {
    getline( cin, s );
    if( s == "." ) break;
    int maru1 = 0, maru2 = 0;
    int kaku1 = 0, kaku2 = 0;
    int prev = -1;
    bool flag = true;
    for(int i=0; i<s.size(); i++) {
      if( s[i] == '(' ) {
	maru1++;
	prev = 0;
      }
      if( s[i] == '[' ) {
	kaku1++;
	prev = 2;
      }
      if( s[i] == ')' ) {
	if( prev == 2 ) {flag = false; break;}
	prev = 1;
	maru2++;
	if( maru2 > maru1 ) {flag = false; break;}
      }
      if( s[i] == ']' ) {
	if( prev == 0 ) {flag = false; break;}
	prev = 3;
	kaku2++;
	if( kaku2 > kaku1 ) {flag = false; break;}
      }
    }

    if( flag ) {
      if( maru1 == maru2 && kaku1 == kaku2 ) cout << "yes" << endl;
      else cout << "no" << endl;
    } else cout << "no" << endl;
  }
}

C++: #include <stdio.h>
#include <stack>


int main(void){
  char c;
  bool ok;

  while(1){
    char s[101] = {0};
    ok = true;
    std::stack<char> st;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	s[i] = '\0';
	break;
      }else{
	s[i] = c;
      }
    }
    
    if(s[0] == '.'){
      break;
    }
    
    for(int i=0; i<101; i++){
      if(s[i] == '.'){
	break;
      }
      if(s[i] == '(' || s[i] == '['){
	st.push(s[i]);
      }else if(s[i] == ')'){
	if(st.empty() || st.top()!='('){
	  ok = false;
	  break;
	}else{
	  st.pop();
	}
      }else if(s[i] == ']'){
	if(st.empty() || st.top() != '['){
	  ok = false;
	  break;
	}else{
	  st.pop();
	}
      }
    }
    
    if(!st.empty()){
      ok = false;
    }
    
    if(ok){
      printf("yes\n");
    }else{
      printf("no\n");
    }
    
  }
  return 0;
}