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(void){
    int i = 0;
    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;
                } 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<string>

std::string str;

bool calc(int p){
	for(int i=p+1;i<str.size();i++){
		if(str[i]=='('){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==')'){
			if(str[p]=='(')return true;
			else return false;
		}
		if(str[i]=='['){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==']'){
			if(str[p]=='[')return true;
			else return false;
		}
	}
	return false;
}

int main(){
	while(1){
		int l=0,l2=0;
		bool p=true;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				if(!calc(i)){
					std::cout<<"no"<<std::endl;
					goto end;
				}
				break;
			}
		}
		if(l==0&&l2==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    string str;
    while(getline(cin,str),str!=".") {
        stack<char> st;
        bool OK=1;
        for(int i=0;i<str.size();i++) {
            if(str[i]=='(') st.push('(');
            if(str[i]==')') {
                if(st.size()==0||st.top()!='(') {OK=0;break;}
                st.pop();
            }
            if(str[i]=='[') st.push('[');
            if(str[i]==']') {
                if(st.size()==0||st.top()!='[') {OK=0;break;}
                st.pop();
            }
        }
        if(st.size()==0&&OK) printf("yes\n"); else printf("no\n");
    }
}

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

using namespace std;

int main(){
	int maru=0,kaku=0;

	string str;
	while(getline(cin,str)){
		if(str.at(0)=='.')break;
		maru=0;
		kaku=0;
		int flag=0;
		stack<int> s;

		for(int i=0;i<str.size();i++){
			if(str.at(i)=='('){
				maru++;
				s.push(1);
			}
			else if(str.at(i)==')' && maru>0){
				if(s.top()==1){
					maru--;
					s.pop();
				}
				else{
					cout<<"no"<<endl;
					flag=1;
				}
			}
			if(str.at(i)=='['){
				kaku++;
				s.push(2);
			}
			else if(str.at(i) ==']' &&kaku>0){
				if(s.top()==2){
					kaku--;
					s.pop();
				}
				else{
					cout<<"no"<<endl;
					flag=1;
				}
			}
			if(flag==1)break;
		}
		if(flag==1)continue;

		if(maru==0&&kaku==0&&flag==0){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}

	return 0;
}

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

using namespace std;

int main()
{
  string str;

  while(!cin.eof()){
    getline(cin, str);
    if(str == ".") break;
    bool f = true;
    stack<char> stk;
    for(int i = 0; i < str.size(); i++){
      if(str[i] == '(' || str[i] == '[') stk.push(str[i]);
      else if(str[i] == ']'){
	if(stk.empty()){
	  f = false;
	  break;
	} else if(stk.top() == '[') stk.pop();
	else break;
      } else if(str[i] == ')'){
	if(stk.empty()){
	  f = false;
	  break;
	} else if(stk.top() == '(') stk.pop();
	else break;
      }
    }

    cout << ((stk.empty() && f)? "yes" : "no") << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <stack>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31)) /*オーバーフローしない程度に大きい数*/
#define MOD 1000000007
int main(void){
    // Your code here!
    
    while(1){
        char line[200];
        rep(i,0,200) line[i] = 0;
        // string str(100,0);
        cin.getline(line,sizeof(line));
        // rep(i,0,100){
        //     if(line[i]!=0){
        //         str.push_back(line[i]);    
        //     }
        // }
        // cout << str << endl;
        // if(str[0]=='.') break;
        if(line[0]=='.') break;
        int maru=0,kaku=0,f=0,last=0;//0:( 1:[
        stack<int> q;
        int i = 0;
        while(1){
                if(line[i]=='('){
                    maru++;
                    q.push(0);
                    // cout << "maru" << maru << endl;
                    
                } 
                if(line[i]=='['){
                    kaku++; 
                    q.push(1);
                    // cout << "kaku" << kaku << endl;
                } 
                if(line[i]==')'){
                    maru--;
                    if(!(q.empty())){
                        if(q.top()==1) f=1;    
                        q.pop();
                    }  
                    // cout<< "maru" << maru << endl;
                } 
                if(line[i]==']'){
                    kaku--;
                    if(!(q.empty())){
                        if(q.top()==0) f=1;    
                        q.pop();
                    }
                    // cout<< "kaku" << kaku << endl;
                } 
                if(maru<0){
                    f=1;   
                }
                if(kaku<0){
                    f=1;    
                }
                if(line[i]=='.'){
                    f=1;
                }
                if(f==1) break;
                i++;
        }
        if(maru==0&&kaku==0){
            cout << "yes" << endl;
        } else{
            cout << "no" << endl;
        }
        
    }
    
}

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

int main(){
	while(1){
		string s;
		getline(cin,s);
		
		if(s[0]=='.')break;
		
		int ra=0;
		int rb=0;
		int la=0;
		int lb=0;
		
		for(int i=0;i<s.size();i++){
			if(s[i]=='(')la++;
			if(s[i]=='[')lb++;
			if(s[i]==')'&&la!=0)ra++;
			if(s[i]==']'&&lb!=0)rb++;
			
			if(s[i]==')'&&la==0){
				la=-939313243;
			}
			if(s[i]==')'&&lb==0){
				ra=-939313243;
			}
		}
		if(la==ra&&rb==lb){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
	
	return 0;
}