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 <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	string str; while (getline(cin, str) && str[0] != '.' && str.size() != 1)
	{
		int id = 0;
		stack<int> stck;
		rep(i, (int)str.size())
		{
			switch (str[i])
			{
				case '(':	stck.push(1);	break;
				case '[': stck.push(2); break;
				case ')': 
					if (stck.size() == 0) { id = 1; }
					else if (stck.top() == 1) { stck.pop(); }
					else { id = 1; } break;
				case ']': 
					if (stck.size() == 0) { id = 1; }
					else if (stck.top() == 2) { stck.pop(); }
					else { id = 1; } break;
			}
		}
		if (stck.size() != 0 || id == 1) { printf("no\n"); }
		else { printf("yes\n"); }
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>

using namespace std;

string str;

int skip(int idx) {
  while (str[idx] != '(' && str[idx] != '[' &&
         str[idx] != ')' && str[idx] != ']' && str[idx] != '.') {
    idx++;
  }
  return idx;
}

char corre(char c) {
  if (c == '[') {return ']';}
  if (c == '(') {return ')';}
}

int inKakko(int idx, char kakko) {
  //fprintf(stderr, "inKakko\n");
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    if (str[idx] == '.') {
      return -1;
    } else if (str[idx] == corre(kakko)) {
      //fprintf(stderr, "matched %c\n", kakko);
      return idx + 1;
    } else if (str[idx] == '(' || str[idx] == '[') {
      idx = inKakko(idx + 1, str[idx]);
      if (idx < 0) {
        return -1;
      }
    } else {
      return -1;
    }
  }
}

bool _solve(int idx) {
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    switch (str[idx]) {
    case '.':
      return true;
    case '(':
    case '[':
      idx = inKakko(idx + 1, str[idx]);
      // fprintf(stderr, "idx=%d\n", idx);
      if (idx < 0) {
        return false;
      }
      break;
    case ')':
    case ']':
      return false;
    }
    //fprintf(stderr, "e%d, %c\n", idx, str[idx]);
  }
}

void solve() {
  if (_solve(0)) {
    printf("yes\n");
  } else {
    printf("no\n");
  }
}

int main() {
  while (true) {
    getline(cin, str);
    //fprintf(stderr, "start\n");
    if (str == ".") {
      return 0;
    }
    solve();
  }
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<string>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
// #define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int main() {
	string line;
	char left_paren;
	bool is_yes;
	vector<char> left_parens;

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

		left_parens.clear();
		is_yes = true;

		rep(i,line.size()) {
			if (line[i] == '(') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == '[') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == ')') {
				left_paren = left_parens.back();
				left_parens.pop_back();
				if (left_paren != '(') {
					is_yes = false;
				}
			}
			else if (line[i] == ']') {
				left_paren = left_parens.back();
				left_parens.pop_back();
				if (left_paren != '[') {
					is_yes = false;
				}
			}
		}
		if (left_parens.size() > 0)
			is_yes = false;

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

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string a;
int saiki(int,int);
int main(){
  int ans;
  while(1){
    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]==')'){
      if(n==1)return i;
    }
    else if(a[i]==']'){
      if(n==2)return i;
    }
    else if(a[i]=='.'){
      if(n==0)return 0;
    }
  }
  return -1;
  
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    getline(cin, S);
    while(S.length() - 1){
        stack<char> st;
        bool flag = 0;
        for(char c:S){
            if(c == '[' || c == '(')st.push(c);
            if(c == ']' || c == ')'){
                if(st.size() == 0){
                    flag = 1;
                    break;

                }
                char t = st.top();
                st.pop();
                if(!(t == '[' && c == ']' || t == '(' && c == ')')){
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag && st.size() == 0)cout << "yes" << endl;
        else    cout << "no" << endl;
        getline(cin, S);
    }
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;


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

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	string str;
	while(getline(cin, str) && str != "."){
		solve(str);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;
stack<char> t;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".")
		break;
		int m=0,k=0;
		t.push('a');
		for(int i=0;i<s.size();i++){
			if(s[i]=='(' || s[i]=='[')
			t.push(s[i]);
			if(t.top()=='(' && s[i]==')' || t.top()=='[' && s[i]==']')
			t.pop();
			else if(t.top()!='(' && s[i]==')' || t.top()!='[' && s[i]==']'){
				t.push('x');
				break;
			}
		}
		if(t.top()=='a')
		cout<<"yes"<<endl;
		else
		cout<<"no"<<endl;
		
	}
	return 0;
}