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

using namespace std;

int main()
{
	stack<char> s;

	while (true){
		char str[128];
		fgets(str, sizeof(str), stdin);

		if (str[0] == '.'){
			break;
		}

		while (!s.empty()){
			s.pop();
		}

		bool flag = true;
		for (int i = 0; str[i] != '.'; i++){
			if (str[i] == '(' || str[i] == '['){
				s.push(str[i]);
			}

			if (str[i] == ')'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '('){
					s.pop();
				}
				else if (s.top() == '['){
					flag = false;
					break;
				}
			}
			if (str[i] == ']'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '['){
					s.pop();
				}
				else if (s.top() == '('){
					flag = false;
					break;
				}
			}
		}

		if (flag || !s.empty()){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

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

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

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	bool flag;
	while(1){
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(1){
			if(letter[i] == '.') break;
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			}
			i++;
		}
		if(st.empty() == false)
		cout << "yes" << endl;
		while(flag == true)
			st.pop();
	}
	return 0;
}

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

using namespace std;

int main(){
		while(1){
				char a[110];
				fgets(a,110,stdin);
				if(a[0]=='.')break;
				int n=strlen(a);
				int i;
				stack<int> st;
				for(i=0;i<n;i++){
						if(a[i]=='['){
								st.push(1);
						}else if(a[i]==']'){
								if(st.empty()==1){
										cout<<"no"<<endl;
										break;
								}
								if(st.top()==1){
										st.pop();
								}else{
										cout<<"no"<<endl;
										break;
								}
						}else if(a[i]=='('){
								st.push(2);
						}else if(a[i]==')'){
								if(st.empty()==1){
										cout<<"no"<<endl;
										break;
								}
								if(st.top()==2){
										st.pop();
								}else{
										cout<<"no"<<endl;
										break;
								}
						}
				}
				if(i==n)cout<<"yes"<<endl;
		}
		return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

stringstream ss;

int expect(string,int,char);
bool solve(string s){
    for(int i=0;i<s.length();i++){
        if(s[i] == '('){
            return expect(s,i+1,')')!=-1;
        }else if(s[i] == '['){
            return expect(s,i+1,']')!=-1;
        }else{
            return false;
        }
    }
    return true;
}

int expect(string s,int p,char c){
    if(s[p] == '('){
        int p2 = expect(s,p+1,')');
        if(p2 == -1) return -1;
        if(s[p2+1] == c) return p2+1;
    }else if(s[p] == '['){
        int p2 = expect(s,p+1,']');
        if(p2 == -1) return -1;
        if(s[p2+1] == c) return p2+1;
    }else if(s[p] == c){
        return p;
    }else{
        return -1;
    }
}

int main(){
    string s;
    while(getline(cin,s)){
        string ss;
        for(int i=0;i<s.length();i++){
            if(s[i] == '(' or s[i] == ')' or
               s[i] == '[' or s[i] == ']') ss += s[i];
        }
        if(solve(ss)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

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

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

      if(check)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }
}

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

using namespace std;

string hoge;
string hogehoge;
stack<char> foo;

int main(void){

  while(1){

    while( !(foo.empty() ) ){
      foo.pop();
    }

    getline( cin , hoge );
    if( hoge == "." )break;

    hogehoge = "";
    for( int i = 0 ; i < hoge.size() ; i++ ){
      if( hoge[i] == '[' || hoge[i] == ']' || hoge[i] == '(' || hoge[i] == ')' ){
	hogehoge += hoge[i]; 
      }
    }

    for( int i = 0 ; i < hogehoge.size() ; i++ ){
      if(hogehoge[i] == '[' ) foo.push(hogehoge[i]);      
      if(hogehoge[i] == '(' ) foo.push(hogehoge[i]);
      if(hogehoge[i] == ']' ){
	if( !( foo.empty() ) && foo.top() == '[' ){
	  foo.pop();
	}
	else goto bad;
      } 
      if(hogehoge[i] == ')' ){
        if( !(foo.empty())  && foo.top() == '(' ){
          foo.pop();
        }
        else goto bad;
      }
    }
    if( foo.empty() ){
    cout << "yes" << endl;
    continue;
    }
  bad:
    cout << "no" << endl;
  }
  return 0;
}