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


bool dfs(string s){
//    cout << "dfs :" << s << endl;
    if(s=="") return true;

    vector<string> vs;
    string ss;
    int a=0,b=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='(') a++;
        else if(s[i]==')') a--;
        else if(s[i]=='[') b++;
        else if(s[i]==']') b--;
        ss += s[i];
        if(i!=0 && a==0 && b==0){
            vs.push_back(ss);
            ss="";
        }
    }

    if(a!=0 || b!=0){
//        cout << "a or b is not 0" << endl;
        return false;
    }

//    cout << " vs " << endl;
//    for(auto v : vs){
//        cout << v << endl;
//    }

    for(int i=0;i<vs.size();i++){
        string t = vs[i];
        char s = t[0];
        char e = t[t.size()-1];
        if(!((s=='('&&e==')')||(s=='['&&e==']'))){
//            cout << " not match " << endl;
            return false;
        }
        if(!dfs(t.substr(1,t.size()-2))){
//            cout << "dfs is not true" << endl;
            return false;
        }
    }
    return true;
}

void solve(string s){
    string ss;
    for(char c : s) if(c=='[' || c==']' || c=='(' || c==')') ss += c;

//    cout << ss << endl;
    bool f = dfs(ss);
    if(f) cout << "yes" << endl;
    else cout << "no" << endl;
}

int main(){
    string s;
    while(getline(cin,s)){
        if(s==".") break;
        solve(s);
    }
}

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

string str;

void solve(){
    stack<int>S;
    for(int i=0;i<str.size();i++){
        if(str[i]=='(')S.push(1);
        else if(str[i]=='[')S.push(0);
        else if(str[i]==')'){
            if(S.empty()||S.top()!=1){
                cout<<"no"<<endl;
                return;
            }
            S.pop();
        }
        else if(str[i]==']'){
            if(S.empty()||S.top()!=0){
                cout<<"no"<<endl;
                return;
            }
            S.pop();
        }
    }
    if(S.empty())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}
int main(){
    while(getline(cin,str),str!=".")solve();
    return 0;
}

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

int main()
{
	string line;
	while (getline(cin,line) && line != ".")
	{
		stack<char> st;
		bool flag = true;
		for (int i = 0; i < line.size(); i++)
		{
			char c = line.at(i);
			if ((c == ']' || c == ')') && st.size() < 1)
			{
				flag = false;
				break;
			}
			if (c == ']')
			{
				if (st.top() == '[')
				{
					st.pop();
				}
				else
				{
					flag = false;
					break;
				}
			}
			else if (c == ')')
			{
				if (st.top() == '(')
				{
					st.pop();
				}
				else
				{
					flag = false;
					break;
				}
			}
			else if (c == '[')
			{
				st.push(c);
			}
			else if (c == '(')
			{
				st.push(c);
			}
		}

		if (flag)
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
	return 0;
}

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

using namespace std;

bool ok (string s)
{
    stack<char> stk;
    for (int i=0; i<s.size(); i++)
    {
        if (s[i]=='(') stk.push('(');
        if (s[i]=='[') stk.push('[');
        if (s[i]==')')
        {
            if (stk.empty()) return false;
            else if (stk.top()!='(') return false;
            else stk.pop();
        }
        if (s[i]==']')
        {
            if (stk.empty()) return false;
            else if (stk.top()!='[') return false;
            else stk.pop();
        }
    }
    return true;
}

int main()
{
    vector<string> s;
    string t;
    while (1)
    {
        getline(cin, t);
        if (t==".") break;
        s.push_back(t);
    }
    for (int i=0; i<s.size(); i++) cout<<(ok(s[i])? "yes\n" : "no\n");
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
using namespace std;
int main() {
	string a;
	while (getline(cin,a)&&a != ".") {
		vector<char>b;
		bool l = true;
		vector<char>::iterator it = b.begin(), it2;
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == '(' || a[i] == '[') {
				b.push_back(a[i]);
			}
			else if (a[i] == ')' || a[i] == ']') {
				if (b.size() != 0) {
					it = b.end();
					it--;
					if (!((a[i] == ')' && (*it) == '(') || (a[i] == ']' && (*it) == '['))) {
						l = false;
					}
					b.erase(it);
				}
				else
					l = false;
			}
		}
		if (l&&b.size()==0) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

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

int main(){

  string str;

  while(getline(cin, str)){
    if(str[0]=='.') break;

    int cc=0, sc=0, cnt=0;
    bool ch=true, f[100];
    for(int i=0;i<str.size();i++){
      if(f[cnt-1]){
	if(str[i]==']'){
	  ch=false;
	  cout<<"no"<<endl;
	  break;
	}
      }else{
	if(str[i]==')'){
	  ch=false;
	  cout<<"no"<<endl;
	  break;
	}
      } 
      if(str[i]=='('){
	cc++;
	f[cnt++]=true;
      }
      if(str[i]==')'){
	cc--;
	cnt--;
      }
      if(str[i]=='['){
	sc++;
	f[cnt++]=false;
      }
      if(str[i]==']'){
	sc--;
	cnt--;
      }

      if(cc<0||sc<0){
	ch=false;
	cout<<"no"<<endl;
	break;
      }
    }

    if(ch) cout<<"yes"<<endl;
  }
  
  return 0;
}