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 <cstring>
#include <stack>
using namespace std;
int main(){
  string str;
  string tmp;
  while(getline(cin, str) && str != "."){
    int p = 0, q = 0;
    bool flag = 1;
    tmp = "";
    
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '[' || str[i] == '(' || str[i] == ']' || str[i] == ')'){
	tmp += str[i];
      }
    }
    
    stack<char> st;
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' || tmp[i] == '[') st.push(tmp[i]);
      else if(tmp[i] == ')'){
	if(st.empty() || st.top() != '(') flag = 0;
	else st.pop();
      }
      else if(tmp[i] == ']'){
	if(st.empty() || st.top() != '[') flag = 0;
	else st.pop();
      }
    }
      
	
    
      /*for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' && tmp[i+1] == ']') flag = 0;
      if(tmp[i] == '[' && tmp[i+1] == ')') flag = 0;
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      //printf("p = %d, q = %d\n", p, q);
      if(p < 0 || q < 0){
	flag = 0;
	break;
      }
      if(tmp[i] == '(') p++;
      if(tmp[i] == '[') q++;
      if(tmp[i] == ')') p--;
      if(tmp[i] == ']') q--;
    }
    if(p != 0 || q != 0) flag = 0;
    cout << tmp << endl;
    printf("p = %d, q = %d\n", p, q);*/
    if(flag == 1) cout << "yes" << endl;
    else cout << "no" << endl;    
  }
  return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
int t[17][17];
int dp[64 * 1024];
int main() {
	string buf;
	while (getline(cin, buf), buf != ".") {
		vector<char> s;
		bool f = true;
		for (auto a : buf) {
			switch (a) {
			case '(':
			case '[':
				s.push_back(a);
				break;
			case ')':
				if (s.back() != '(')f = false;
				s.pop_back();
				break;
			case ']':
				if (s.back() != '[')f = false;
				s.pop_back();
				break;
			}
		}
		if (!s.empty())f = false;
		cout << (f ? "yes" : "no") << endl;
	}
	return 0;
}

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

string str;
stack<char> blacket;

void init() {
	str.clear();
	while(!blacket.empty())
		blacket.pop();
}

bool input() {
	getline(cin, str);
	if(str.size() == 1 && str[0] == '.')
		return false;

	return true;
}

bool solve() {
	for(int i = 0; i < str.size(); i++) {
		switch(str[i]) {
			case '(':
				blacket.push(str[i]);
				break;
			case '[':
				blacket.push(str[i]);
				break;
			case ')':
				if(blacket.size() > 0 && blacket.top() == '(')
					blacket.pop();
				else
					return false;
				break;
			case ']':
				if(blacket.size() > 0 && blacket.top() == '[')
					blacket.pop();
				else
					return false;
				break;
		}
	}

	if(blacket.size() > 0)
		return false;

	return true;
}

int main() {
	while(init(), input()) {
		if(solve())
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	
	return 0;
}

C++: #include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#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<iostream>
#include<stack>
#include<algorithm>
using namespace std;

int main(){
    string str, t = "()[]";
    while(getline(cin,str) && str != "."){
        stack<char> s;
        bool judge = true;
        for(char x : str){
            if(!count(t.begin(), t.end(), x))    continue;

            if(s.empty() || x == '(' || x == '['){
                s.push(x);
            }else if(!s.empty() && (x == ')' && s.top() == '(') || (x == ']' && s.top() == '[')){
                s.pop();
            }else{
                judge = false;
                break;
            }
        }
        
        if(s.empty() && judge)  cout << "yes" << endl;
        else                    cout << "no" << endl;
    }
    return 0;
}

C++: ///
// File:  1173.cpp
// Author: ymiyamoto
//
// Created on Sun Nov 12 17:50:22 2017
//

#include <cstdint>
#include <iostream>
#include <istream>
#include <stack>

using namespace std;

int32_t main()
{
  while (true) {
    string str;
    getline(cin, str);
    if (str.size() == 0 || str[0] == '\n') break;

    stack<char> s;
    for (uint32_t i = 0; i < str.size(); i++) {
      if (str[i] == '(') {
        s.push('(');
      } else if (str[i] == ')') {
        if (!s.empty() && s.top() == '(') {
          s.pop();
        } else {
          s.push('*');
          break;
        }
      } else if (str[i] == '[') {
        s.push('[');
      } else if (str[i] == ']') {
        if (!s.empty() && s.top() == '[') {
          s.pop();
        } else {
          s.push('*');
          break;
        }
      }
    }

    if (s.empty()) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
  string str;
  bool ok;

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

C++: #include <stdio.h>
#include <string.h>
#include <stdlib.h>

int stack[50000];
int size=0;
int main(void){
	while(1){
		char c;
		int flag=0;
		size=0;
		int flag2=1;
		while((c=getchar())!='.'){
			flag=1;
			if(!flag2)continue;
			if(c=='(')stack[size++]=1;
			if(c=='[')stack[size++]=2;
			if(c==')'){
				if(size==0)flag2=0;
				else{
					size--;
					if(stack[size]!=1)flag2=0;
				}
			}
			if(c==']'){
				if(size==0)flag2=0;
				else{
					size--;
					if(stack[size]!=2)flag2=0;
				}
			}
		}
		c=getchar();
		if(!flag)break;
		if(size!=0)flag2=0;
		printf("%s\n",flag2?"yes":"no");
	}
	return 0;
}