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<vector>
using namespace std;

int main (){
	string a;
	bool IsOk = true; bool b = false; bool IsFinish = false;
	vector<int> v;
	while (cin >> a){
		if (IsFinish==true&&a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}else{
			b = false;
			IsFinish = false;
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (v.empty()==false&&v.back()!=1){
					IsOk = false;
				}
				else if (v.empty() == false){
					v.pop_back();
				}
			}
			else if (a[i] == 91){//[
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (v.empty() == false && v.back() != 0){
					IsOk = false;
				}
				else{
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (v.empty()==false){
					IsOk = false;
				}
				if (IsOk == true){cout << "yes"<<endl;
				}else{            cout << "no" <<endl;}
				IsOk = true; 
				v.clear();
				IsFinish = true;
			}
		}
	}
	return 0;
}

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

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

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; 
    f=0,count=0,count1=0;
    while(1){ 
      scanf("%c",&ch[j]); 
      if(ch[j]=='.')break; 
      j++; 
    } 
    if(j==0)break; 
    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 count2=0; 
  if(ch[x]==')'){ 
    count1--; 
    for(int i=x-1;i>=0;i--) 
      if(ch[i]=='('){ 
	for(int j=x-1;j>i;j--) 
	  if(ch[j]=='[')count2++; 
	  else if(ch[j]==']')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;j--) 
	  if(ch[j]=='(')count2++; 
	  else if(ch[j]==')')count2--; 
	break; 
      } 
  } 
  if(count2>0)f=1; 
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s)&&s!="."){
        string c;
        for(int i=0;i<s.size();i++)if(s[i]==')'||s[i]=='('||s[i]=='['||s[i]==']')c+=s[i];
        int d=1;
        stack<char> w;
        for(int i=0;i<c.size();i++){
            if(c[i]=='['||c[i]=='(')w.push(c[i]);
            else if((c[i]==']'&&w.top()=='[')||(c[i]==')'&&w.top()=='('))w.pop();
            else break;
        }
        if(w.empty())cout<<"yes"<<endl;
        else fail:cout<<"no"<<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()||st.top()!='('){
					flag=false;
					break;
				}
				else if('('==st.top()){
					st.pop();
				}
			}
			
			else if(str[i]==']'){
				if(st.empty()||st.top()!='['){
					flag=false;
				}
				else if('['==st.top()){
					st.pop();
				}
			}
		}
		
		if(flag && st.empty()){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}

		
	}
}

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

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

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

char c[101];

int main(){
while(1){
	cin.getline(c, sizeof(c));

	int len = 0;
	while(1){
		if(c[len] == '.') break;
		len++;
	}
	if(len == 0) break;
	
	
	
	
	int rl=0, rr=0, gl=0, gr=0;
	bool flag = true;
	for(int i=0; i < len; i++){
		if(c[i] == '(') rl++;
		else if(c[i] == ')') rr++;
		else if(c[i] == '[') gl++;
		else if(c[i] == ']') gr++;
		
		//check!
		if(rl < rr) flag = false;
		if(gl < gr) flag = false;
	}
	//check!
	if(rl != rr) flag = false;
	if(gl != gr) flag = false;
	
	if(flag) cout << "yes" << endl;
	else cout << "no" << endl;
	
}//end	
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  while(getline(cin,s)){
    if(s=="") return 0;
    stack<int> ss;
    for(int i=0;i<s.length();i++){
      if(s[i]=='('){
        ss.push(0);
      }else if(s[i]=='['){
        ss.push(1);
      }else if(s[i]==')'){
        if(ss.empty()){
          cout << "no" << endl;
          goto next;
        }
        if(ss.top()==0){
          ss.pop();
        }else{
          cout << "no" << endl;
          goto next;
        }
      }else if(s[i]==']'){
        if(ss.empty()){
          cout << "no" << endl;
          goto next;
        }
        if(ss.top()==1){
          ss.pop();
        }else{
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << "yes" << endl;
    next:
    continue;
  }
  return 0;
}