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 <stack>
using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(1){
    getline(cin,s);
    if(s[0]=='.')break;
    stack<char> sta;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(') sta.push('(');
      else if(s[i]=='[') sta.push('[');
      else if(s[i]==')'){
	if(sta.empty()){
	  sta.push('1');
	  break;
	}
	if(sta.top()=='('){
	  sta.pop();
	}
	else break;
      }
      else if(s[i]==']'){
	if(sta.empty()){
	  sta.push('1');
	  break;
	}
	if(sta.top()=='['){
	  sta.pop();
	}
	else break;
      }
    }
    if(sta.empty()){
      cout<<"yes"<<endl;
    }
    else cout<<"no"<<endl;
    
  }

  return 0;
}

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

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i]== '\n' && str[i-1]=='.') break;
        }
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }else if(st.empty()){
                if(str[i]==')' || str[i]==']') judge = false;
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	while (true) {
		string s;
		getline(cin, s);
		if (s == ".") return 0;
		stack<int> gogo;
		int ok = 1;
		for (int i = 0; i < s.length(); ++i) {
			if (s[i] == '(') {
				gogo.push(0);
			}
			else if (s[i] == ')') {
				if (gogo.empty() == true || gogo.top() == 1) {
					ok = 0;
					break;
				}
				gogo.pop();
			}
			else if (s[i] == '[') {
				gogo.push(1);
			}
			else if (s[i] == ']') {
				if (gogo.empty() == true || gogo.top() == 0) {
					ok = 0;
					break;
				}
				gogo.pop();
			}
		}
		if (gogo.empty() == true && ok == 1) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
}

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

int main(){
	string s;
	string left("([");
	string right(")]");
	while(getline(cin,s),s!="."){
		stack<char> acc;
		for(int unsigned i = 0;i<s.size();i++){
			for(int unsigned j=0;j<left.size();j++){
				if(s[i] == left[j]){
					acc.push(right[j]);	
				}
			}
			if(find(right.begin(),right.end(),s[i]) != left.end() && !acc.empty()){
				if(acc.top() == s[i]){
					acc.pop();
				} else {
					break;
				}
			}
		}
		if(acc.empty()){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int main() {
  string line;
  while (getline(cin, line)) {
    if (line == ".") break;
    stack<char> s;
    const int N = line.size();
    bool ok = true;
    
    rep(i,N) {
      if ((line[i] == '[') || (line[i] == '(')) {
        s.push(line[i]);
      } else if (line[i] == ']') {
        if (s.size() && s.top() == '[') {
          s.pop();
        } else {
          ok = false; break;
        }
      } else if (line[i] == ')') {
        if (s.size() && s.top() == '(') {
          s.pop();
        } else {
          ok = false; break;
        }
      }
    }

    if (s.size()) ok = false;
    
    printf("%s\n", ok ? "yes" : "no");
  }
  return 0;
}

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

int main()
{
	string str;
	while(getline(cin, str)){
		if(str[0] == '.' && str.size() == 1)
			break;
		string tmp = "";
		for(unsigned i=0;i<str.size();i++){
			if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']'){
				unsigned a = tmp.size();
				if(a!=0) a--;
				if((tmp[a] == '(' && str[i] == ')' )||(tmp[a] == '[' && str[i] == ']'))
					tmp.erase(a);
				else
					tmp += str[i];
			}
		}
		if(tmp.size()==0)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}