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>

using namespace std;

int main()
{
	string s;
	int stack[103]={0};
	int pointer=0;
	bool flag=true;

	getline(cin,s);
	while (s!=".")
	{
		for (int i=0;i<s.length();++i)
		{
			if (s[i]=='(') stack[pointer++] = 1;
			if (s[i]=='[') stack[pointer++] = 2;
			if ((s[i]==')')&&(stack[--pointer]!=1)) {flag=false; break;}
			if ((s[i]==']')&&(stack[--pointer]!=2)) {flag=false; break;}
		}

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

		flag = true;
		pointer = 0;
		getline(cin,s);
	}
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

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

		if(st.empty()){
			p("yes");
		}else{
			p("no");
		}
	}

	return 0;
}

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

int main()
{
    while(true){
        string s;
        getline(cin, s);
        int l = s.size();
        if(l == 1 && s[0] == '.') break;
        int a[250] {0};
        int now = 0;
        bool balance = true;
        for(int i = 0; i < l - 1; i++){
            if(s[i] == '('){
                a[now] = 1;
                now++;
            }
            if(s[i] == '['){
                a[now] = 2;
                now++;
            }
            if(s[i] == ')'){
                now--;
                if(now < 0){
                    balance = false;
                    break;
                }
                else if(a[now] != 1){
                    balance = false;
                    break;
                }
            }
            if(s[i] == ']'){
                now--;
                if(now < 0){
                    balance = false;
                    break;
                }
                else if(a[now] != 2){
                    balance = false;
                    break;
                }
            }
        }
        if(now != 0) balance = false;
        if(balance) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

string input;

int find(int a, int p) {
	int btn[2] = {};
	FOR(i, p, input.size()) {
		if(btn[0] < 0 || btn[1] < 0)
			return 1;
		if(a) {
			if(input[i] == '[')
				btn[0]++;
			if(input[i] == ']')
				btn[0]--;
			if(input[i] == '(')
				btn[1]++;
			if(input[i] == ')') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
		else {
			if(input[i] == '(')
				btn[0]++;
			if(input[i] == ')')
				btn[0]--;
			if(input[i] == '[')
				btn[1]++;
			if(input[i] == ']') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
	}
	return 1;
}


int main() {
	while(getline(cin, input)) {
		if(input == ".") break;
		int cnt = 0;
		REP(i, input.size()) {
			if(input[i] == '(')
				cnt += find(1, i);
			if(input[i] == '[')
				cnt += find(0, i);
		}
		cout << (cnt ? "no" : "yes") << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string a;
int c;
int saiki(int,int);
int main(){
  int ans;
  while(1){
    c=0;
    a.clear();
    getline(cin,a);
    if(a==".")break;
    ans=saiki(0,0);

    //out 
    if(ans==-1)cout << "no" << endl;
    else cout << "yes" << endl;
  }
  return 0;
}
int saiki(int I,int n){//n:1=( 2=[
  for(int i=I;i<a.size();i++){
    if(a[i]=='('){
      i=saiki(i+1,1);
      if(i==-1)return -1;
    }
    else if(a[i]=='['){
      i=saiki(i+1,2);
      if(i==-1)return -1;
    }
    else if(a[i]==')'){
      c++;
      if(n==1){
	c--;
	return i;
      }
    }
    else if(a[i]==']'){
      c++;
      if(n==2){
	c--;
	return i;
      }
    }
    else if(a[i]=='.'){
      if(c!=0)return -1;
      if(n==0)return 0;
    }
  }
  return -1;
  
}

C++: #include <bits/stdc++.h>

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    vector<string> ans;
    while(true){
        char S[256];
        fgets(S, 256, stdin);
        int lenS = strlen(S);
        if(S[0] == '.' && lenS == 2) break;
        bool ok = true;
        stack<char> st;
        st.push('A');
        rep(i, lenS){
            if(S[i] == ')'){
                char tp = st.top();
                st.pop();
                if(tp != '('){
                    ok = false;
                    break;
                }
            }
            else if(S[i] == ']'){
                char tp = st.top();
                st.pop();
                if(tp != '['){
                    ok = false;
                    break;
                }
            }
            else if(S[i] == '('){
                st.push(S[i]);
            }
            else if(S[i] == '['){
                st.push(S[i]);
            }
        }
        if(st.empty() || st.top() != 'A') ok = false;
        if(ok) ans.push_back("yes");
        else ans.push_back("no");
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	string input;
	while(1){
		getline(cin,input);
		if(input.length()==1&&input[0]=='.')break;
		stack<bool> data;
		bool f=true;
		for(int i=0;i<input.length();i++){
			if(input[i]=='[')data.push(true);
			if(input[i]==']'){
				if(data.empty()||!data.top()){
					f=false;
					break;
				}else data.pop();
			}
			if(input[i]=='(')data.push(false);
			if(input[i]==')'){
				if(data.empty()||data.top()){
					f=false;
					break;
				}else data.pop();
			}
		}
		if(f&&data.empty()){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
}

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

using namespace std;

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