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++: // 2012/05/14 Tazoe

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

int main()
{
	while(true){
		string str;
		getline(cin, str);

		if(str==".")
			break;

		stack<char> S;

		bool flg = true;
		for(int i=0; flg&&str[i]!='.'; i++){
			if(str[i]=='('){
				S.push(str[i]);
			}
			else if(str[i]=='['){
				S.push(str[i]);
			}
			else if(str[i]==')'){
				if(S.empty()||S.top()!='('){
					flg = false;
				}
				else{
					S.pop();
				}
			}
			else if(str[i]==']'){
				if(S.empty()||S.top()!='['){
					flg = false;
				}
				else{
					S.pop();
				}
			}
		}

		if(flg&&S.empty()){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	return 0;
}

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

const int size = 101;
string line;
stack <char> S;

bool dfs( int i ) {
    if ( i == line.size() ) return S.empty();
    if ( line[i] == '(' || line[i] == '[' ) {
        S.push( line[i] );
    } else if ( line[i] == ')' || line[i] == ']' ) {
        if ( S.empty() ) return false;
        if ( S.top() == '(' && line[i] == ']' ) return false;
        if ( S.top() == '[' && line[i] == ')' ) return false;
        S.pop();
    }
    return dfs( i+1 );
}

int main() {
    while ( getline( cin, line ) && line != "." ) {
        S = stack<char>();
        bool result = dfs( 0 );
        cout << ( result ? "yes" : "no" ) << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main(){
  int i,ib;
  char a,s[100];
  while(1){
    i=0;
    scanf("%c",&a);
    if(a=='.')break;
    else if(a=='('){
      s[i]='(';
      i++;
    }else if(a==')'){
      s[i]=')';
      i++;
    }else if(a=='['){
      s[i]='[';
      i++;
    }else if(a==']'){
      s[i]=']';
      i++;
    }
    while(1){
      scanf("%c",&a);
      if(a=='.'){
	if(i==0){
	  printf("yes\n");
	  break;
	}else {
	  printf("no\n");
	  break;
	}
      }else if(a=='('){
	s[i]='(';
	i++;
      }else if(a==')'){
	if(s[i-1]=='(')i--;
	else {
	  s[i]=')';
	  i++;
	}
      }else if(a=='['){
	s[i]='[';
	i++;
      }else if(a==']'){
	if(s[i-1]=='[')i--;
	else {
	  s[i]=']';
	  i++;
	}
      }
    }
    scanf("%c",&a);
  }
  return 0;
}

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

using namespace std;

void load(vector<string>& datas){
    while(1){
        string str;
        while(1){
            char word;
            if(!cin){
                datas.pop_back();
                return;
            }
            cin >> word;
            str += word;
            if(word == '.') break;
        }
        datas.push_back(str);
    }
}



int main()
{
    vector<string> datas;
    
    load(datas);
    
    for(auto data: datas){
        vector<bool> brackets;
        
        for(auto itr = data.begin(); itr != data.end(); itr++){
            if(*itr == '[') brackets.push_back(true);
            else if(*itr == '(') brackets.push_back(false);
            else if(*itr == ']' && brackets.size()) {
                if(brackets.back() == true) 
                    brackets.pop_back();
            }
            else if(*itr == ')' && brackets.size()) {
                if(brackets.back() == false) 
                    brackets.pop_back();
            }
        }
        if(brackets.size()) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    
    return 0;
}

C++: // AOJ 1173 The Balance of the world
#include <iostream>
#include <string>
#include <stack>
using namespace std;

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

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

int main() {
   while (1) {
      string s;
      getline(cin, s);
      if (s == ".") break;

      stack<char> stk;
      bool ok = true;
      int n = s.size();
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.empty() || stk.top() != '(') {
               ok = false;
               break;
            }
            stk.pop();
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = false;
               break;
            }
            stk.pop();
         }
      }
      if (stk.empty() && ok) {
         puts("yes");
      } else {
         puts("no");
      }
   }
}

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

int main(){
	while(1){		
		string str;
		cin >> str;
		if(str[0] == '.') break;
		//string::iterator ite = str.end()--;
		if(str[str.size()-1] != '.'){
			while(1){
				string s;
				cin >> s;
				str.append(s);
				//ite = s.end()--;
				if(s[s.size()-1] == '.') break;
			}
		}

		stack<char> sta;
		string s = "yes";
		for(int i = 0;str[i] != '.'; 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;
	}
	return 0;
}

C++: #include<cstdio>
#include<vector>
using namespace std;
int main(){
  while(1){
    char t;
    vector<int> s;
    int f=0;
    while(1){
      scanf("%c",&t);
      if(t=='.')break;
      f=1;
      if((t!='('&&t!=')'&&t!='['&&t!=']')||f!=1)continue;
      else if(t=='(')s.push_back(1);
      else if(t=='[')s.push_back(2);
      else if(!s.empty()){
	if(s.back()==1&&t==')')s.pop_back();
	else if(s.back()==2&&t==']')s.pop_back();
      }
      else if(t==']'||t==')')f=2;
    }scanf("%c",&t);
    if(f==0)break;
    else if(f==1&&s.empty())printf("yes\n");
    else printf("no\n");
  }
  return 0;
}