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 <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 (ok && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }
}

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

using namespace std;

int check(char c){
  if(c == '[' || c == '(') return 2;
  if(c == ']' || c == ')') return 1;
  return 0;
}

int isOK(char c, char in){
  if(in == ']' && c == '[') return 1;
  if(in == ')' && c == '(') return 1;
  // cout << " " << c << " " << in << endl;
  return 0;
}

int main(){

  string in;
  while(getline(cin,in)){
    if(in == ".") break;
    stack<char> S;
    int status = 1;
    for(int i = 0; i < in.length(); i++){
      int j = check(in[i]);
      if(j == 2){
	S.push(in[i]);
	//	cout << " " << in[i] << endl;
      }
      if(j == 1) {
	if(S.size() == 0){
	  status = 0;
	  break;
	}
	if(!isOK(S.top(),in[i])){
	  status = 0;
	  break;
	}
	S.pop();
      }
    }
    if(status) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	std::string str;
	getline(cin, str);

	while (str[0] != '.' && str.length() != 0) {
		std::stack<int> check;
		bool much = true;
		for (int i = 0; i < str.length()+1; i++) {
			if (much) {
				if (str[i] == '(') {
					check.push(1);
				}
				if (str[i] == ')') {
					if (check.empty()) {
						much = false;
					} else {
						if (check.top()!=1) {
							much = false;
						}
						check.pop();
					}
				}
				if (str[i] == '[') {
					check.push(2);
				}
				if (str[i] == ']') {
					if (check.empty()) {
						much = false;
					} else {
						if (check.top()!=2) {
							much = false;
						}
						check.pop();
					}
				}
			}
		}
		if (much) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
		getline(cin, str);
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void test(int );
int f,count,count1;
char ch[101]; 
int main(){
  while(1){
    int j=0;
    while(1){
      scanf("%c",&ch[j]);
      if(ch[j]=='.')break;
      j++; 
    }
    if(j==0)break;
    count=0,count1=0;

    for(int i=0;i<j;i++){
      if(ch[i]=='[')count++;
      else if(ch[i]=='(')count1++;
      else if(ch[i]==']' || ch[i]==')')test(i);
      if(count1<0||count<0||f==1)break; 
    }

    if(count==0&&count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char a;
    scanf("%c",&a);
  }
  return 0;
}

void test(int x){
  f=0;
  int f1=0;
  int count2=0;
  if(ch[x]==')'){
    count1--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='('){
	for(int j=x-1;j>i;i++)
	  if(ch[i]=='[')count2++;
	  else if(ch[i]==']')count2--;
	break;
      }
  }

  else if(ch[x]==']'){
    count--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='['){
	for(int j=x-1;j>i;i++)
	  if(ch[i]=='(')count2++;
	  else if(ch[i]==')')count2--;
	break;
      }
  }
  if(count2>=1)f=1;
}

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();
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
	string str;

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

		
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void) {
	while(1) {
		string str;
		bool balance = true;
		stack<char> sbracket;

		getline(cin, str);
		if(str == ".") break;
		for(int i = 0; str[i] != '.'; i++) {
			if(str[i] == '(' || str[i] == '[') {
				sbracket.push(str[i]);
			}
			if(str[i] == ')') {
				if(sbracket.size() == 0 || sbracket.top() != '(') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
			if(str[i] == ']') {
				if(sbracket.size() == 0 || sbracket.top() != '[') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
		}
		if(sbracket.size() > 0) balance = false;
		printf(balance ? "yes\n" : "no\n");
	}
	return 0;
}

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

bool isYes(char input[]);

int main()
{
	char Input[10000][101];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		yesno[i] = isYes(Input);
		if(Input[0] == '.') break;
		i++;
	}
	for(int j=0; j<i; j++){
		if(yesno[i]){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	int prep[50], prepnum=0, p=3;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=0;
		} else if(Input[i] == '['){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=1;
		} else if(Input[i] == ')'){
			if(p!=0){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=1){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}