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 <stack>
#include <string>

using namespace std;

int main(){
  char str[101];
 
  while ( 1 ){
    string s = "yes";
    cin.getline( str, sizeof( str ) );
    if ( str[0] == '.' ) break;
    stack<char> sta;
    for ( int i = 0; str[i] != '\0'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
        sta.push( str[i] );
      }else if ( str[i] == ')' ){
        if ( sta.top() == '(' ){
          sta.pop();
	}else{
	  s = "no";
	  break;
	}
      }else if ( str[i] == ']' ){
        if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  s = "no";
	  break;
	}
      }
    }
    if ( !sta.empty() ) s = "no";
    cout << s << endl;
  }
}

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

using namespace std;
string s;
int main() {
G:
	while (getline(cin, s) && s != ".") {
		stack<char> p;
		for (int i = 0;i < s.length();i++) {
			if (s[i] == '(' || s[i] == '[')p.push(s[i]);
			if (s[i] == ')') { if (p.empty() || p.top() != '(') { cout << "no" << endl;goto G; }p.pop(); }
			if (s[i] == ']') { if (p.empty() || p.top() != '[') { cout << "no" << endl;goto G; }p.pop(); }
		}
		cout << (p.empty() ? "yes" : "no") << endl;
	}
	return 0;
}

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

int main(){

  int a=0,s=0,q=0;
  bool flag[100];
  string c,r;

  while(true){
    cin>>c;
    r = c.substr(0,1);
    if(r==".") break;

    flag[q]=true;
    
    while(true){
      r = c.substr(a,1);
      if(r==".") break;

      if(r=="("||r=="[") ++s;
      if(r==")"||r=="]") --s;
      if(s<0&&flag[q]==true){
	flag[q]==false;
	break;
      }
      ++a;
    }
    s=0;
    a=0;
    ++q;
  }
  
  for(int i=0; i<q;++i){
    if(flag[i]){
      cout << "yes" << endl;
    }else cout << "no" << endl;;
  }

  
  return 0;
}

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

using namespace std;

main(){
  char c;
  while(scanf("%c", &c) != EOF){
    if(c == '.') break;
    stack<char> data;
    bool f = true;
    while(c != '\n'){
      if(f){
        if(c == '(' || c == '[') data.push(c);
        if(c == ')'){
          if(data.size() == 0 || data.top() != '(') f = false;
          else data.pop();
        }
        if(c == ']'){
          if(data.size() == 0 || data.top() != '[') f = false;
          else data.pop();
        }
      }
      scanf("%c", &c);
    }
    cout << (f ? "yes" : "no") << endl;
  }
}

C++: #include<iostream>
#include<stdio.h>
#include<string>

std::string str;

bool calc(int p){
	for(int i=p+1;i<str.size();i++){
		if(str[i]=='('){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==')'){
			if(str[p]=='(')return true;
			else return false;
		}
		if(str[i]=='['){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==']'){
			if(str[p]=='[')return true;
			else return false;
		}
	}
	return false;
}

int main(){
	while(1){
		int l=0,l2=0;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='(')l++;
			if(str[i]==')')l--;
			if(str[i]=='[')l2++;
			if(str[i]==']')l2--;
			if(l<0||l2<0){
				puts("no");
				goto end;
			}
			if(str[i]=='('||str[i]=='['){
				if(!calc(i)){
					puts("no");
					goto end;
				}
			}
		}
		if(l==0&&l2==0)puts("yes");
		else puts("no");
		end:;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };
 
 
string a;
stack<string> s;
 
int main() {
    while ( !!( getline( cin, a ) ) && a != "." ) {
        bool is_yes = true;
        for ( int i = 0; i < a.size(); i++ ) {
            if ( a[ i ] == '(' ) {
                s.push( "(" );
            }
            if ( a[ i ] == '[' ) {
                s.push( "[" );
            }
            if ( a[ i ] == ')' ) {
                if ( !s.size() || s.top() != "(" ) {
                    is_yes = false;
                    break;
                }
                s.pop();
            }
            if ( a[ i ] == ']' ) {
                if ( !s.size() || s.top() != "[" ) {
                    is_yes = false;
                    break;
                }
                s.pop();
            }
        }
        if ( is_yes && !s.size() ) {
            printf( "yes\n" );
        }
        else {
            printf( "no\n" );
        }
        while ( s.size() ) {
            s.pop();
        }
    }
    return 0;
}

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

int main(){
  string s;
  stack<char> c;
  c.push('\0');
  while(getline(cin,s)){
    if(s == ".")break;
    while(c.size() != 1)c.pop();
    for(int i = 0;i < s.length();i++){
      if(s[i] == '(' || s[i] == '[') c.push(s[i]);		
      else if(s[i]-1 == c.top() || s[i]-2 == c.top()) c.pop();
    }
    if(c.size() == 1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<stack>

using namespace std;

#define INF 999999999

int main(){
	int i, j;
	char s[101];
	stack<int> st;
	int flag;
	
	while(1){
		fgets(s, sizeof(s), stdin);
		if(s[0]=='.')break;
		flag = 1;
		while(!st.empty()) st.pop();
		
		for(i=0;s[i]!='.';i++){
			if(s[i]=='(') st.push(1);
			else if(s[i]=='[') st.push(2);
			else if(s[i]==')'){
				if(st.empty()||st.top()==2){
					flag = 0;
					break;
				}
				else{
					st.pop();
				}
			}
			else if(s[i]==']'){
				if(st.empty()||st.top()==1){
					flag = 0;
					break;
				}
				else{
					st.pop();
				}
			}
		}
		
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}