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

int main(){
    string str;
    bool ans;
    getline(cin, str);
    while(str != "."){
        stack<int> bra;
        ans = true;
        for(string::iterator it=str.begin();it!=str.end();++it){
            switch(*it){
                case '(':
                    bra.push(1);
                    break;
                case '[':
                    bra.push(0);
                    break;
                case ')':
                    if(bra.empty()) ans = false;
                    else{
                        if(bra.top()!=1) ans = false;
                        bra.pop();
                    }
                    break;
                case ']':
                    if(bra.empty()) ans = false;
                    else{
                        if(bra.top()!=0) ans = false;
                        bra.pop();
                    }
                    break;
            }
            if(!ans) break;
        }
        if(!bra.empty()) ans = false;
        cout << (ans?"yes":"no") << endl;
        getline(cin, str);
    }
}

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

int main(void){
	while(true){
		string s;
		getline(cin,s); // getline() is 便利 -> http://www.ci.seikei.ac.jp/matsumoto/opro/05.pdf
		if(s[0]=='.') break;
		stack<char> st; // push() -> top() -> pop()
		bool err = false;
		for(int i = 0; i < s.size(); ++i){
			if(s[i] == '(' || s[i] == '['){
				st.push(s[i]);
			}else if(s[i] == ')' || s[i] == ']'){
				if(st.empty() || s[i] != (st.top()=='('?')':']')){
					err = true;
					break;
				}else{
					st.pop();
				}
			}
		}
		if(!err && st.empty()){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	return 0;
}

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

using namespace std;
int main(){
	string str;
	while(getline(cin,str)&& str!="."){
		string z;

		for(int i=0;i<str.size();i++)
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				z+=str[i];
	
		stack<char> s;
		bool f=true;

		for(int i=0;i<z.length();i++){

			if(z.empty() || z[i]=='(' || z[i]=='[')
				s.push(z[i]);

			else if( (s.top()=='(' && z[i]==')') || (s.top()=='[' && z[i]==']') )
					s.pop();
			else{
				f=false;
				break;
			}
		}
		cout << (f && s.empty()?"yes":"no") << endl;
	}
}

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

using namespace std;


int main(){

	string s;
	
	while(getline(cin,s),s!="."){
		stack<char> a;
		string ans="yes";
		for(int i=0;i <(int) s.size() ;i++){

			if(s[i]=='('||s[i]=='[')
				a.push(s[i]);
			else if(s[i]==')'){
				if(a.empty()){
					ans="no";
					break;
				}
				else{
					if(a.top()=='('){
						a.pop();
						
					}
					else{
						ans="no";
						break;
					}
				}
			}
			else if(s[i]==']'){
				if(a.empty()){
					ans="no";
					break;
				}
				else{
					if(a.top()=='[')
						a.pop();
					else{
						ans="no";
						break;
					}
				}
			}

		}
			cout<<ans<<endl;
	}



}

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

int main(){
  vector < char > moji;
  string str;
  int i;
  while(getline(cin,str)){
    int flag = 0;
    if( str == "." ) break;
    
    int len = str.size();

    moji.clear();
      
    for( i = 0; i < len; i++ ){
      if( str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']'){
	moji.push_back(str[i]);
      }
    }
   
    int len2 = moji.size();
    if( len2 == 1 ) flag = 1;
    
    for( i = 0; i < len2-1; i++ ){
      if( moji[0] == ')' ) flag = 1;
      if( moji[0] == ']' ) flag = 1;
      
      if( moji[i] == '[' && moji[i+1] == ')' ) flag = 1;
      if( moji[i] == '(' && moji[i+1] == ']' ) flag = 1;
    }

    if( flag == 0 ) cout << "yes" << endl;
    else cout << "no" << endl;

  }
  return 0;
}

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

bool q2(){
    char c;
    bool check = true;
    stack<char> st;
    st.push('0');
    if(scanf("%c",&c) && c == '.')return false;
    while(c != '.'){
        switch(c){
            case '(':
                st.push('(');break;
            case '[':
                st.push('[');break;
            case ')':
                if(st.top()!='('){check=false;break;}
                st.pop();break;
            case ']':
                if(st.top()!='['){check=false;break;}
                st.pop();break;
            default:
                break;
        }
        scanf("%c",&c);
    }
    cout << (check ? "yes" : "no") << '\n';
    scanf("%c",&c);
    return true;
}

int main()
{
    while(q2());
}

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

int main(){
	string s;
	while(getline(cin, s), s != "."){
			stack<char> st;
			bool flag = true;
			for(int i = 0; i < (int)s.size(); i++){
				if(s[i] == '(' ) st.push('(');
				else if(s[i] == '[' ) st.push('[');

				if(s[i] == ')' ){
					if(st.empty() or st.top() != '('){
						flag = false;
						break;
					}
					if(!st.empty()) st.pop();
				}
				else if(s[i] == ']' ){
					if(st.empty() or st.top() != '['){
						flag = false;
						break;
					}
					if(!st.empty()) st.pop();
			}
		}
		if(!st.empty()) flag = false;
		if(flag) cout << "yes" << endl;
		else cout << "no" << endl;
		while(!st.empty()) st.pop();
	}
	return 0;
}