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<stack>
#include<cstdio>
#include<cstring>

using namespace std;

int main(){
	while(1){
		char s[128]; fgets(s,128,stdin);
		int n=strlen(s);
		if(s[n-1]=='\n') s[--n]='\0';
		if(strcmp(s,".")==0) break;

		bool ok=true;
		stack<char> St;
		for(int i=0;i<n;i++){
			if(s[i]=='(') St.push(s[i]);
			if(s[i]=='[') St.push(s[i]);
			if(s[i]==')') if(St.empty() || St.top()=='['){ ok=false; break; } else St.pop();
			if(s[i]==']') if(St.empty() || St.top()=='('){ ok=false; break; } else St.pop();
		}
		if(!St.empty()) ok=false;

		puts(ok?"yes":"no");
	}

	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int ro,so,i,j,k,b[1000]={},p=0;
  while(str.size()!=1||str[0]!='.'){
    ro=0;so=0;k=0;p=0;
    for(i=0;i<str.size();i++){
      if(str[i]=='(') {
	ro++;
	p++;
	b[p]=1;
      }
      if(str[i]=='[') {
	so++;
	p++;
	b[p]=2;
      }	  
      if(str[i]==')') {
	if(b[p]==1) {
	  ro--;
	  p--;
	}
	else k=1;
      }
      if(str[i]==']') {
	if(b[p]==2) {
	  so--;
	  p--;
	}
	else k=1;
      }

      if(ro<0||so<0) k=1;
    }
    if(k==0&&ro==0&&so==0) cout << "yes" << endl;
    else cout << "no" << endl;
    getline(cin,str);
  }
  return 0;
}

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

int main()
{
  string str;

  while (getline(cin,str))
  {
    if ((str.length() == 1) && (str[0] = '.')) return 0;

    int paren = 0;
    int blacket = 0;
    stack<char> p;
    bool flag = true;

    for (int i=0;i<str.length();i++)
    {
      if (str[i] == '(')
      {
        paren++;
        p.push('(');
      }
      else if (str[i] == ')')
      {
        paren--;
        if (paren < 0) { flag = false; break; }
        if (p.top() != '(') { flag = false; break; }
        p.pop();
      }
      else if (str[i] == '[')
      {
        blacket++;
        p.push('[');
      }
      else if (str[i] == ']')
      {
        blacket--;
        if (blacket < 0) { flag = false; break; }
        if (p.top() != '[') { flag = false; break; }
        p.pop();
      }
    }
    if (flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 201

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

bool calc(){
  char s[SIZE];
  stack<char> st;
  
  scanf("%[^\n]%*[\n]",s);

  if(s[0]=='.') return false;
  
  for(int i=0;s[i]!='.';i++){
    if(s[i]=='[' || s[i]=='(') st.push(s[i]);
    if(s[i]==']'){
      if(st.empty() || st.top()!='['){
	puts("no");
	return true;
      }
      st.pop();
    }
    if(s[i]==')'){
      if(st.empty() || st.top()!='('){
	puts("no");
	return true;
      }
      st.pop();
    }
  }

  if(st.empty()) puts("yes");
  else puts("no");
  
  return true;
}

int main(){
  
  while(calc());
  
  return 0;
}

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

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

      if(s[i] == ')'){
        if(st.empty()){
          flag = true;
          break;
        }
        if(st.top() == '('){
          st.pop();
        }else{
          flag = true;
          break;
        }
      }
      if(s[i] == ']'){
        if(st.empty()){
          flag = true;
          break;
        }
        if(st.top() == '['){
          st.pop();
        }else{
          flag = true;
          break;
        }
      }
    }

    if(flag || !st.empty())
      cout << "no" << endl;
    else
      cout << "yes" << endl;
  }
  
  return 0;
}

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

int main(void) {
    char str[105];
    while(1){
        
        cin.getline(str, sizeof(str));

        if(str[0] == '.') break;
        stack<char> s;
        s.push('0');
        int flag = 1;
        for(int i = 0; str[i] != '\0'; i++){
            if(str[i] == '(') s.push(')');
            if(str[i] == '[') s.push(']');
            if(str[i] == ')'){
                if(s.top() == ')'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
            if(str[i] == ']'){
                if(s.top() == ']'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
        }
        if(flag) cout << "yes" << endl;
    }
    return 0;

}

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

using namespace std;

int main(){
	string a;
	bool IsOk = true;
	bool b = false;
	bool IsFinish = false;
	vector<int> v;
	while (cin >> a){
		if (IsFinish==true&&a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}else{
			b = false;
			IsFinish = false;
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (v.empty() == false){
					if (v.back() != 1){
						IsOk = false;
					}
					v.pop_back();
				}
				else{
					IsOk = false;
				}
				
			}
			else if (a[i] == 91){//[
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (v.empty() == false && v.back() != 0){
					IsOk = false;
				}
				else{
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (!v.empty()){
					IsOk = false;
				}
				if (IsOk == true){cout << "yes"<<endl;
				}else{            cout << "no" <<endl;}
				IsOk = true; 
				v.clear();
				IsFinish = true;
			}
		}
	}
	return 0;
}

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

using namespace std;

void solve(){
	string s;
	while(getline(cin,s)&&s!="."){
		stack<char> sk;
		bool ok=true;
		for(int i=0;i<s.size();i++){
			if(s[i]=='(')sk.push('(');
			else if(s[i]=='[')sk.push('[');
			else if(s[i]==')'){
				if(sk.size()&&sk.top()=='('){
					sk.pop();
				}
				else{
					ok=false;
					break;
				}
			}
			else if(s[i]==']'){
				if(sk.size()&&sk.top()=='['){
					sk.pop();
				}
				else{
					ok=false;
					break;
				}
			}
		}
		if(ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}