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;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;

int main() {
    string str;

    while (true) {
        getline(cin, str);
        if (str == ".") break;

        bool flag=true;
        for (int i=str.size()-1; i>=0; --i) {
            if (str[i] == '(' or str[i] == '[') {
                int t=(str[i] == '(' ? 1 : 0);
                str[i]='.';
                flag=false;
                for (int j=i+1; j<str.size(); ++j) {
                    if (str[j] == ')' and t) {
                        str[j]='.';
                        flag=true;
                        break;
                    }
                    else if (str[j] == ')' and !t) {
                        break;
                    }
                    else if (str[j] == ']' and !t) {
                        str[j]='.';
                        flag=true;
                        break;
                    }
                    else if (str[j] == ']' and t) {
                        break;
                    }
                }
            }
            if (!flag) break;
        }

        rep(i, str.size()) {
            if (str[i] == '(' or str[i] == ')' or str[i] == '[' or str[i] == ']') flag=false;
        }

        cout << (flag ? "yes" : "no") << endl;
    }

}

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

int main(){
	while(1){
		int l=0,l2=0;
		std::string str;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='(')l++;
			if(str[i]==')')l--;
			if(str[i]=='[')l2++;
			if(str[i]==']')l2--;
		}
		if(l==0&&l2==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void) {
	string ch;
	getline(cin, ch);
	while (ch[0] != '.') {
		int i,ci = 0,cj=0;
		for (i = 0; ch[i] != '.'; i++) {
			if (ch[i] == '(') ci++;
			else if (ch[i] == ')') ci--;
			else if (ch[i] == '[') cj++;
			else if (ch[i] == ']') cj--;
			if (ci < 0 || cj < 0) break;
		}
		if (ci || cj) {
			cout << "no" << endl;
		}
		else {
			cout << "yes" << endl;
		}
		getline(cin, ch);
	}
	return 0;
}

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

bool isPair(char top, char input) {
    if ((top == '(' && input ==')') 
        || (top == '[' && input ==']')) {
        return true;
    } 
    return false;
}

void check(string str) {
    stack<char> st;

    for (int i = 0; i < str.size(); ++i) {
        if (!st.empty()) {
            char top = st.top();
            if (isPair(top, str[i])) {
                st.pop();
                continue;
            }
        }
        
        if (str[i] == '(' || str[i] == ')' 
            || str[i] == '[' || str[i] == ']') {
            st.push(str[i]);
        }
    }

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

int main() {
    string str;
    while(getline(cin, str), str.front() != '.') {
        check(str);
    }
    return 0;
}

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

using namespace std;

int main(){
	string str;
	int i;
	
	while(1){
		getline(cin, str);
		if(str == ".")
			break;
		stack<char> tmp;
		tmp.push('$');
		for(i = 0; i < str.size(); i++){
			if(str[i] == '(' || str[i] == '[')
				tmp.push(str[i]);
			
			else if(str[i] == ')'){
				if(tmp.top() == '(')
					tmp.pop();
				else break;
			}
			
			else if(str[i] == ']'){
				if(tmp.top() == '[')
					tmp.pop();
				else break;
			}
		}
		if(i == str.size() && tmp.size() == 1)
			cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

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

int main(){
  char str[100];
  string s = "yes";
  
  while ( 1 ){
    cin.getline( str, sizeof( str ) );	//receive
    if ( str[0] == '.' ) break;
    	stack<char> sta;
    for ( int i = 0; str[i] != '.'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
        sta.push( str[i] );
      }else if ( str[i] == ')' ){
        if ( sta.empty() ){
        	s = "no";
        	break;
        }
        if ( sta.top() == '(' ){
          sta.pop();
		}else{
	  		s = "no";
	  		break;
		}
      }else if ( str[i] == ']' ){
        if ( sta.empty() ){
        	s = "no";
        	break;
        }
        if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  		s = "no";
	  		break;
		}
      }
    }
    if ( !sta.empty() ) s = "no";
      cout << s << endl;
  }
}

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=='('){
      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--;
      }
    }
    
    if(s!='.'){  
    while(true){
      cin>>c;
      //    cout<<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=-1111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-1111;
      }
    }
    }
    if(maru==0&&shikaku==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    if(s=='.')break;
    if(c!='.'){
      while(true){
	cin>>c;
	//    cout<<c;
	if(c=='.')break;
      }
    }
    maru=0;
    shikaku=0;
  }
  

  return 0;
}

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

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