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(){
	string S;
	int n=0;
	stack<int> T[200000];
	bool hantei=true;

	while (true){
		getline(cin,S);
		hantei=true;
		if(S=="."){
			break;
		}
		for(int i=0;i<S.size();i++){
			if(S[i]=='(' || S[i]=='['){
				T[n].push(S[i]);
			}
			if(S[i]==')' || S[i]==']'){
				if(T[n].empty()){
					hantei=false;
				}
				else{
					if((T[n].top()=='(' && S[i]==']')|| (T[n].top()=='[' && S[i]==')')){
						hantei=false;
					}
					T[n].pop();
				}
			}
		}
		if(T[n].empty()==false){
			hantei=false;
		}
		cout<<(hantei?"yes":"no")<<endl;
		n++;
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 1000000000
#define EPS 1e-10

string str;

string k[3];
int f[1000000];

vector<string> ans_list;

int main(){

	k[0] = "()";
	k[1] = "[]";

	while (true){
		getline(cin, str);
		if (str == ".")
			break;

		int num;
		int f_c = -1;

		for (num = 0; num < str.length(); num++){
			if (k[0][0] == str[num]){
				f_c++;
				f[f_c] = 0;
			}
			else if (k[1][0] == str[num]){
				f_c++;
				f[f_c] = 1;
			}
			else if (k[0][1] == str[num]){
				if (f_c < 0 || f[f_c] != 0)
					break;
				f_c--;
			}
			else if (k[1][1] == str[num]){
				if (f_c < 0 || f[f_c] != 1)
					break;
				f_c--;
			}
		}

		if (num == str.length() && f_c < 0)
			ans_list.push_back("yes");
		else
			ans_list.push_back("no");


	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

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

using namespace std;

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

C++: // AOJ 1173

#include <iostream>
#include <string>
#include <stack>
using namespace std;

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

C++: #include<iostream>
#include<string>
using namespace std;
int main(void) {
	string ch;
	char a[101] = {};
	getline(cin, ch);
	while (ch[0] != '.') {
		int i,j=0;
		for (i = 0; ch[i] != '.'; i++) {
			if (ch[i] == '(' || ch[i] == '[') {
				a[j] = ch[i];
				j++;
			}
			else if (ch[i] == ')' || ch[i] == ']') {
				j--;
				if (a[j] != ch[i]) {
					cout << "no" << endl;
					break;
				}
			}
		}
		if (j == 0) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
		getline(cin, ch);
	}
	return 0;
}

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

int main()
{
	string str;
	while (getline(cin, str)){
		int c = 0, s = 0, f = 0;
		for (int p = 0; p < str.size(); p++){
			if (str[p] == '('){
				f = 1;
				c++;
			}
			else if (str[p] == ')'){
				if (f == 2) break;
				f = 0;
				c--;
			}
			else if (str[p] == '['){
				f = 2;
				s++;
			}
			else if (str[p] == ']'){
				if (f == 1) break;
				f = 0;
				s--;
			}
			if (c < 0 || s < 0) break;
		}
		if (!c && !s) puts("yes");
		else puts("no");
	}
	
	return 0;
}

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	while(1){
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(letter[i] != '\0'){
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
			}
			}
			i++;
		}
		int p = st.size();
		if(st.empty())
		cout << "yes" << endl;
		else
		cout << "no" << endl;
		for(int i = 0; i < st.size(); i++)
			st.pop();
	}
	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; if(!sta.empty())sta.pop(); break;
				case '(': sta.push(2); break;
				case ')': if(sta.top() != 2)f = 0; if(!sta.empty())sta.pop(); break;
			}
			if(f == 0) break;
		}
		
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		
	}
	return 0;
}

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

using namespace std;

string setup(string s){
  string ns = "";
  for(int i=0; i<s.length(); i++){
    if(s[i] == '(' || s[i] == ')' || s[i] == '[' || s[i] == ']'){
      ns += s[i];
    }
  }
  return ns;
}

int main(void){
  
  while(1){
    string line;
    getline(cin,line);
    
    if(line == ".") break;
    
    // remove other chars
    line = setup(line);
    int a, b;
    
    while((a=line.find("()")) != -1 || (b=line.find("[]")) != -1){
      if(a != -1){
        line.erase(a, 2);
      } else if(b != -1){
        line.erase(b, 2);
      }
    }
    
    if(line.length() != 0){
      cout << "no" << endl;
    } else {
      cout << "yes" << endl;
    }
    
  }
  
  return 0;
}

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

int main(){
  char str[100];
 
  while ( 1 ){
    string s = "yes";
    cin.getline( str, sizeof( str ) );
    if ( str[0] == '.' ) break;
    stack<char> sta;
    for ( int i = 0; str[i] != '\0'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
        sta.push( str[i] );
      }else if ( str[i] == ')' ){
        if ( sta.top() == '(' ){
          sta.pop();
	}else{
	  s = "no";
	  break;
	}
      }else if ( str[i] == ']' ){
        if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  s = "no";
	  break;
	}
      }
    }
    if ( !sta.empty() ) s = "no";
    cout << s << endl;
  }
}