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>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>

using namespace std;
 
const double eps=1e-10;

const int dy[]={-1,-1,0,1,1, 1, 0,-1};
const int dx[]={ 0, 1,1,1,0,-1,-1,-1};

int main()
{

	string s;
	while(getline(cin,s),s!="."){
		for(int i=s.size()-1;i>=0;i--){
			if(s[i]!='(' && s[i]!=')' && s[i]!='[' && s[i]!=']') s.erase(s.begin()+i);
		}

		int pos1,pos2;
		while( (pos1=s.find("()"))!=string::npos ||  (pos2=s.find("[]"))!=string::npos){

			if(pos1!=string::npos){
				s.replace(pos1,2,"");
				continue;
			}

			if(pos2!=string::npos){
				s.replace(pos2,2,"");
				continue;
			}


		}

		if(s=="") cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}

	return 0;
}

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

bool isYes(char input[]);

int main()
{
	char Input[101];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		isYes(Input){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
		if(Input[0] == '.') break;
		i++;
	}

	return 0;
}

bool isYes(char Input[])
{
	int prep[50], prepnum=0, p=3;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=0;
		} else if(Input[i] == '['){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=1;
		} else if(Input[i] == ')'){
			if(p!=0){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=1){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

string s;

bool f() {
	int maru = 0, kaku = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '(')maru++;
		if (s[i] == ')') {
			if (maru == 0)return false;
			maru--;
		}
		if (s[i] == '[')kaku++;
		if (s[i] == ']') {
			if (kaku == 0)return false;
			kaku--;
		}
	}
	if (maru == 0 && kaku == 0)return true;
	else return false;
}

int main() {
	while (getline(cin, s)&&s!=".") {
		cout << (f() ? "yes" : "no") << endl;
	}
}

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

using namespace std;

int main()
{
  int end;
  stack <char> sta;

  while(1){
    string v;
    string t;
    string g;
    end = 0;

    while(1){
      cin>>v;
      t = t+v;

      for(auto s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

    if(t == "."){
      break;
    }

    for(auto e : t){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        auto t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        auto t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }

    if(g != "no"){
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

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

int main(){
	string s;
	while(getline(cin, s), s != "."){
		int flg = 1;
		stack<char> word;
		for(int i=0 ; i < s.size() ; i++){
			if(s[i]=='[') word.push('[');
			if(s[i]=='(') word.push('(');
			if(s[i]==']'){
				if(!word.empty()&&word.top()=='[') word.pop();
				else{
					flg = 0;
				}
			}
			if(s[i]==')'){
				if(!word.empty()&&word.top()=='(') word.pop();
				else{
					flg = 0;
				}
			}
		}
			
			if(flg==1&&word.empty()) cout << "yes" << endl;
			else cout << "no" << endl;
		}
			return 0;
	}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  while(true){
    vector<string> s;
    while(true){
      string tmp;
      getline(cin,tmp);
      s.push_back(tmp);
      if(tmp[tmp.size()-1] == '.')break;
    }
    //    REP(i,s.size())
    //    cout << s[i] <<endl;
    if(s.size()==1&&s[0][0]=='.')break;
    stack<int> st;
    bool is_theory = true;
    REP(i,s.size()){
      REP(j,s[i].size()){
	if(s[i][j] == '(')st.push(1);
	if(s[i][j] == '[')st.push(-1);
      if(s[i][j] == ')')
	if(!st.empty() && st.top() == 1)st.pop();
	else {is_theory = false;break;}
      if(s[i][j] == ']')
	if(!st.empty() && st.top() == -1)st.pop();
	else {is_theory = false;break;}
      }
    }
    if(is_theory && st.empty())cout << "yes" << endl;
    else cout << "no" << endl;
  }
	

  return 0;
}

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

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

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

int main()
{

	string text;

	getline(cin,text);
	while(text[0] != '.'){
		int ans=1 ,brac[100]={0} ,n=0;
		for(int i=0 ; text[i]!='.'; i++){
			//test	cout<<(int)text[i]<<" ";
			if(text[i]=='('){
				brac[n]=1;
				n++;
			}
			if(text[i]==')'){
				if(n==0) ans=0;
				else if(brac[n-1]!=1) ans=0;
				else{
					n--;
					brac[n]=0;
				}
			}
			if(text[i]=='['){
				brac[n]=2;
				n++;
			}
			if(text[i]==']'){
				if(n==0) ans=0;
				else if(brac[n-1]!=2) ans=0;
				else{
					n--;
					brac[n]=0;
				}
			}
			if(ans==0) break;
		}
		if(ans==0 ||  n!=0) cout<<"no"<<endl;
		else cout<<"yes"<<endl;
		getline(cin,text);
	}
}