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>

using namespace std;

int main(){
  char r[202];
  int count = 100;
  char s;
  char c;
  int maru=0;
  int shikaku=0;
  while(true){
    cin>>s;
    if(s=='.')break;
    else if(s=='('){
      r[count++]=')';
      maru++;
    }
    else if(s=='['){
      r[count++]=']';
      shikaku++;
    }
    else if(s==')'){
      if(r[count--]==s){
	maru--;
      }
    }
    else if(s==']'){
      if(r[count--]==s){
	shikaku--;
      }
    }
    
    
    while(true){
      cin>>c;
      if(c=='.'||maru<0||shikaku<0)break;
      else if(c=='('){
	r[count++]=')';
	maru++;
      }
      else if(c=='['){
	r[count++]=']';
	shikaku++;
      }
      else if(c==')'){
	if(r[count-1]==c){
	  count--;
	  maru--;
	}
	else maru=-11111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-11111;
      }
    }

    if(maru==0&&shikaku==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    if(c!='.'){
      while(true){
	cin>>c;
	if(c=='.')break;
      }
    }
    maru=0;
    shikaku=0;
  }
     if(maru==0&&shikaku==0)cout<<"yes"<<endl;
      else cout<<"no"<<endl;
  

  return 0;
}

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

bool solve(string str) {
  stack<char> stk;
  for (char c : str) {
    if (c == '[') {
      stk.push(c);
    } else if (c == '(') {
      stk.push(c);
    } else if (c == ']') {
      if (stk.empty() or stk.top() != '[') {
        return false;
      }
      stk.pop();
    } else if (c == ')') {
      if (stk.empty() or stk.top() != '(') {
        return false;
      }
      stk.pop();
    }
  }
  return stk.empty();
}

int main() {
  string query;
  while (getline(cin, query) and query != ".") {
    cout << (solve(query) ? "yes" : "no" ) << endl;
  }
}

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

stack<char> st;

int main(){
	string s;
	while(getline(cin, s), s != "."){
		int len = s.size();
		bool flag = true;
		for(int i = 0; i < len; i++){
			if(s[i] == '(' ) st.push('(');
			else if(s[i] == '[' ) st.push('[');

			if(s[i] == ')' ){
				if(st.top() != '(' or st.empty()) flag = false;
				else if(st.top() == '(' ) st.pop();
			}
			else if(s[i] == ']' ){
				if(st.top() != '[' or st.empty()) flag = false;
				else if(st.top() == '[') st.pop();
			}
		}
		if(!st.empty() or !st.empty()) flag = false;


		if(flag) cout << "yes" << endl;
		else cout << "no" << endl;
		
		while(!st.empty()) st.pop();
	}

	return 0;
}

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

using namespace std;

stack<char> s;
string input;

int main() {
	bool yes;
	while(1) {
		while(!s.empty()) s.pop();
		yes = true;
		getline(cin,input);
		if (input == ".") break;
		for(int i=0; input[i] != '.'; i++) {
			if(input[i]=='(' || input[i]=='[') s.push(input[i]);
			if(input[i]==')'){
				if(s.empty()) yes = false;
				else if(s.top() == '(') s.pop();
				else yes = false;
			}
			if(input[i]==']'){
				if(s.empty()) yes = false;
				else if(s.top() == '[') s.pop();
				else yes = false;
			}
			//cout << input[i] << ":" << yes << endl;
		}
		if (!s.empty()) yes = false;
		if (yes) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

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

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

int main(void){
	char str[101];
	
	while(1){
		//入力
		fgets(str,101,stdin);
		if(str[0]=='.')break;

		//計算
		stack<int> s;
		s.push(0);
		int flag=1;
		for(int i=0; str[i]!='.'; i++){
			if		(str[i]=='('){
				s.push(1);
			}else if(str[i]=='['){
				s.push(2);
			}else if(str[i]==')'){
				if(s.top()!=1){flag=0; break;}
				s.pop();
			}else if(str[i]==']'){
				if(s.top()!=2){flag=0; break;}
				s.pop();
			}
		}
		if(s.top()!=0){
			flag=0;
		}

		//出力
		if(flag)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	
	return 0;
}

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

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

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;

string removeExceptParens(string);
bool isBalancedParens(string);

int main() {
	vector<string> lines;
	while (true) {
		string line = "";
		getline(cin, line);
		if (line == ".") {
			break;
		}
		lines.push_back(line);
	}

	for (vector<string>::iterator it = lines.begin(); it != lines.end(); it++) {
		string parenRemovedLine = removeExceptParens(*it);
		if(isBalancedParens(parenRemovedLine)){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	// debug
	string end;
	cin >> end;
	// debug

	return 0;
}

string removeExceptParens(string str){
	string result = "";	
	for (string::iterator it = str.begin(); it != str.end(); it++) {
		if (*it == '(' || *it == ')' || *it == '[' || *it == ']') {
			result += *it;
		}
	}
	return result;
}

bool isBalancedParens(string str) {
	if (str == "") {
		return true;
	}
	else {
		string::size_type paren1 = str.find("()");
		string::size_type paren2 = str.find("[]");
		if (paren1 == string::npos && paren2 == string::npos) {
			return false;
		}
		else {
			if (paren1 != string::npos) {
				str.replace((int)paren1, 2, "");
			}
			if (paren2 != string::npos) {
				str.replace((int)paren2, 2, "");
			}
			return isBalancedParens(str);
		}
	}
}