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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main() {
	char b;
	string a;
	int ans,i,j,p=0;
	stack<int> s;
	while (1) {
		ans = 0;
		i = 0;
		while (s.size()!=0) {
			s.pop();
		}
		getline(cin, a);
		F(j,n) {
			if (i == 0 && a[j] == '.') {
				p = 1;
				break;
			}
			if (a[j] == '.') {
				if (s.size()!=0 ){
					ans = 1;
					break;
				}
				break;
			}
			if (a[j] == '(')s.push(1);
			if (a[j] == '[')s.push(2);
			if (a[j] == ')') {
				if (s.size() == 0) {
					ans = 1;
					continue;
				}
				if (s.top() == 1) {
					s.pop();
				}
				else {
					ans = 1;
				}
			}
			if (a[j] == ']') {
				if (s.size() == 0) {
					ans = 1;
					continue;
				}
				if (s.top() == 2) {
					s.pop();
				}
				else {
					ans = 1;
				}
			}
			i = 1;

		}
		if (p == 1)break;
		if (ans == 0)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	while(1){
		string in;
		getline(cin,in);
		if(in[0]=='.') break;
		stack<int> a;
		bool flg = false;
		REP(i,in.size()){
			if(in[i]=='(') a.push(1);
			if(in[i]=='[') a.push(2);
			if(in[i]==')'){
				if(!a.empty()){
					if(a.top()!=1) flg = true;
					a.pop(); 
				}else{
					flg = true;
				}
			}
			if(in[i]==']'){
				if(!a.empty()){
					if(a.top()!=2) flg = true;
					a.pop(); 
				}else{
					flg = true;
				}
			}
		}

		if(flg==false){
			if(!a.empty()) flg = true;
		}
		if(flg) cout << "no" << endl;
		else cout << "yes" << endl;
	}
}

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

int main(){
	while(1){
		string s;
		getline(cin,s);
		
		if(s[0]=='.')break;
		
		int a=0;
		int b=0;
		int ta=0;
		int tb=0;
		
		for(int i=0;i<s.size();i++){
			if(s[i]=='('){
				a++;
				tb=b;
			}
			if(s[i]=='['){
				b++;
				ta=a;
			}
			if(s[i]==')'){
				if(b!=tb){
					b=-1;
					break;
				}
				a--;
			}
			if(s[i]==']'){
				if(a!=ta){
					a=-1;
					break;
				}
				b--;
			}
			if(a<0||b<0)break;
		}
		if(a==0&&b==0){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<list>

int main(){
  using namespace std;
  int i;
  char str[102];
  list<char> ls;
  do{
    fgets(str,102,stdin);
    if(str[0]=='.') break;
    ls.clear();
    for(i=0;str[i]!='.';i++){
      switch(str[i]){
      case '(':
	ls.push_front('(');
	break;
      case ')':
	if(ls.front()!='('){
	  printf("no\n");
	  goto end;
	}
	ls.pop_front();
	break;
      case '[':
	ls.push_front('[');
	break;
      case ']':
	if(ls.front()!='['){
	  printf("no\n");
	  goto end;
	}
	ls.pop_front();
	break;
      }
    }
    if(ls.empty()) printf("yes\n");
    else printf("no\n");
  end:;
  }while(1);
  return 0;
}

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

using namespace std;

namespace Solver {

    string s;
    inline bool Read() {
        getline(cin, s);
        return s != ".";
    }

    inline void Work() {
        stack<char> stk;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '[' || s[i] == '(') {
                stk.push(s[i]);
            } else if (s[i] == ']') {
                if (stk.empty()) {
                    cout << "no" << std::endl;
                    return;
                }
                if (!stk.empty() && stk.top() == '[') stk.pop();
            } else if (s[i] == ')') {
                if (stk.empty()) {
                    cout << "no" << std::endl;
                    return;
                }
                if (!stk.empty() && stk.top() == '(') stk.pop();
            }
        }

        if (stk.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    inline void Solve() {
         while(Read()) Work();
    }
}

int main() {
    Solver::Solve();
}

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

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i]== '\n') break;
        }
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

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

int main(){
	string s;
	while(getline(cin, s)){
		stack<int> st;
		bool ans=true;
		
		while(!st.empty()) st.pop();
		
		for(int i=0; i<s.size(); ++i){
			if(s[i]=='(') st.push(1);	
			else if(s[i]=='[') st.push(2);
			
			if(s[i]==')'){
				if(st.empty()) ans=false;
				else{
					int ch=st.top();
					st.pop();
					if(ch!=1) ans=false;
				}	
			}
			else if(s[i]==']'){
				if(st.empty()) ans=false;
				else{
					int ch=st.top();
					st.pop();
					if(ch!=2) ans=false;	
				}	
			}
			
			if(!ans) break;
		}
		
		if(!st.empty()) ans=false;
		if(s[s.size()-1] != '.') ans=false;
		
		if(ans) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

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

int main() {
	string b;
	int i, c=0,d=0;
	while (1) {
		getline(cin,b);
		for (i = 0; i<(int)b.size(); i++) {
				if (b[i] == '(') { c += 1; }
				if (b[i] == ')') {
					c -= 1;
					if (c < 0) { break; }
				}
				if (b[i] == '[') { d += 1; }
				if (b[i] == ']') { d -= 1;
				if (d < 0) { break; }
				}
		}

		if (b[0]=='.'||b[1]=='.') { break; }
		if (c == 0 && d == 0) {cout << "yes"<<endl; }
			else { cout << "no"<<endl; }
			c = 0, d = 0;
	};
	return 0;
}