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 s;
	while (getline(cin, s))
	{
		if (s == ".") return 0;
		vector<char> ary;
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] == '[') ary.push_back('[');
			if (s[i] == ']') ary.push_back(']');
			if (s[i] == '(') ary.push_back('(');
			if (s[i] == ')') ary.push_back(')');
		}
		int beforeSize = ary.size();
		while (true)
		{
			if (ary.size() == 0)
			{
				cout << "yes" << endl;
				break;
			}
			for (int i = 1; i < ary.size(); i++)
			{
				if ((ary[i - 1] == '[' && ary[i] == ']') ||
					ary[i - 1] == '(' && ary[i] == ')')
				{
					ary.erase(ary.begin() + i);
					ary.erase(ary.begin() + i - 1);
					i--;
				}
			}
			if (beforeSize == ary.size())
			{
				cout << "no" << endl;
				break;
			}
			beforeSize = ary.size();
		}
	}

	return 0;
}

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

int main(void){
    int t;
    int n,m,p;
    int ans;
    string s;
    string str;
    string c;
    vector<int>x;
    while(true) {
        s="";
        while(true){
            getline(cin,str);
            s+=str;
            if(str.back()!='.')s.push_back(' ');
            else break;
        }
        if(s.front()=='.')break;
        t=0;n=0;m=0;p=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='('){t++;c.push_back(s[i]);}
            if(s[i]==')'){
                n++;
                if(c.back()=='['){cout<<"no"<<endl;goto invail;}
                else if(c.size()>0)c.pop_back();
            }
            if(s[i]=='['){m++;c.push_back(s[i]);}
            if(s[i]==']'){
                p++;
                if(c.back()=='('){cout<<"no"<<endl;goto invail;}
                else if(c.size()>0)c.pop_back();
            }
            if(t<n){cout<<"no"<<endl;goto invail;}
            if(m<p){cout<<"no"<<endl;goto invail;}
        }
        cout<<"yes"<<endl;
        invail:;
    }
    return 0;
}

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<<"no"<<std::endl;
				goto end;
			}
		}
		if(l==0&&l2==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

string s;
int l;

int main()
{
    while(getline(cin,s))
    {

        if(s.size() == 1 && s == ".")break;

        int maru = 0, kaku = 0, inmaru = 0, inkaku = 0;
        l = s.size();
        stack<char> bra;
        
        bool ans = true;
        REP(l)
        {

            if(s[i] == '('){ bra.push('(');continue; }
            if(s[i] == '['){ bra.push('[');continue; }

            if(s[i] == ')')
            {
                if(bra.empty() || bra.top() != '('){ans = false; break;}
                bra.pop();
            }
            if(s[i] == ']')
            {
                if(bra.empty() || bra.top() != '['){ans = false; break;}
                bra.pop();
            }
        }
        if(ans) cout<< "yes" << endl;
        else cout << "no" << endl;

    }
    return 0;
}

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

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

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

typedef stack<char> P;

int main()
{
     const char s[5] = "()[]";
     string str;
     while (getline(cin, str), str.size() > 1) {
	  P p;
	  bool flag  =true;
	  for (int i = 0; i < str.size(); i++) {
	       if (str[i] == s[0] || str[i] == s[2]) p.push(str[i]);
	       else if (str[i] == s[1] || str[i] == s[3]) {
		    if (p.size() < 1) {
			 flag = false;
			 break;
		    } else if (str[i] == s[1] && p.top() == s[0]) p.pop();
		    else if (str[i] == s[3] && p.top() == s[2]) p.pop();
		    else {
			 flag = false;
			 break;
		    }
	       }
	  }
	  if (flag && p.size() == 0) cout << "yes" << endl;
	  else cout << "no" << endl;
     }

     return 0;
}

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

int main(){
	std::vector<std::string>Vstr;
	while(1){
		std::string str;
		char bef;
		int count=0;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				count++;
				bef=str[i];
			}else if(str[i]==')'||str[i]==']'){
				count--;
				if(!((str[i]==')'&&bef=='(')||(str[i]==']'&&bef=='['))){
					Vstr.push_back("no");
					goto end;
				}
			}
		}
		if(count==0)Vstr.push_back("yes");
		else Vstr.push_back("no");
		end:;
	}
	for(int i=0;i<Vstr.size();i++)std::cout<<Vstr[i]<<std::endl;
	return 0;
}

C++: #include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	vector<string> s;
	
	while (1) {
		string ss;
		getline(cin, ss);
		if (ss == ".") break;

		int a[2] = {};
		bool flag = true;

		stack<int> st;
	
		for (int j = 0; j < ss.length(); j++) {

			if (ss[j] == '(') st.push(0);
			if (ss[j] == ')') {
				if (st.empty() || st.top() != 0 ) {
					flag = false;
					break;
				}
				else st.pop();
			}
			if (ss[j] == '[') st.push(1);
			if (ss[j] == ']') {
				if (st.empty() || st.top() != 1) {
					flag = false;
					break;
				}
				else st.pop();
			}
		}

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

	}

	return 0;
}