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 <stdio.h>
#include <string.h>
int kakko(char *c,char tmp,int count){
	int flag = 0;
	char wtmp,retmp;
	*c = getchar();
	count++;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	while(*c != '.' && *c != tmp && *c != wtmp){
		if(*c == '(' || *c == '['){
			if(*c == '(')
				retmp = ')';
			else
				retmp = ']';
			flag = kakko(c,retmp,count);
			if(*c != '.')
				*c = getchar();
		}
		if(*c != '.' && *c != tmp && *c != wtmp ){
			*c = getchar();
			count++;
		}
	}
	if(*c == '.' || *c == wtmp)
		flag = 1;
	return flag;
}

int main(void){
	int count = 0, flag = 0;
	char c, tmp;
	c = getchar();
	while(c != '.' || count != 0){
		if(c == '(' || c == '['){
			if(c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(&c,tmp,count);
		}
		if(c == ')' || c == ']')
			flag = 1;
		if(c == '.' || flag == 1){
			if(flag == 0)
				printf("yes\n");
			else
				printf("no\n");
			flag = 0;
			count = 0;
			getchar(); //改行読取ばs
			c = getchar();
		}
		else{
			c = getchar();
			count++;
		}
	}
	return 0;
}

C++: #include <iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main() 
{
	string s;
	while(true)
	{
		getline(cin,s);
		if(s==".")return 0;
		string t;
		//int len=s.size();
	//	cout<<0<<endl;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]==' ')s.replace(i,1,"a");
		}
	//	cout<<s<<endl;
		t=s;
		for(int i=0;i<s.size();i++)
		{
		//	cout<<0<<endl;
			if(s[i]=='(')
			{
				for(int j=i+1;j<s.size();j++)
				{
					if(s[j]==')')
					{
						s.replace(i,1,"a");
						s.replace(j,1,"a");
						break;
					}
					//else if(s[j]==']')break;
				}
			}
			if(s[i]=='[')
			{
				for(int j=i+1;j<s.size();j++)
				{
					if(s[j]==']')
					{
						s.replace(i,1,"a");
						s.replace(j,1,"a");
						break;
					}
					//else if(s[j]==')')break;
				}
			}
		}
	//	cout<<s<<endl;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='('||s[i]==')'||s[i]=='['||s[i]==']')
			{
				cout<<"no"<<endl;
				goto A;
			}
		}
		cout<<"yes"<<endl;
		A:;
		s.clear();
	}
	return 0;
}

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

int check( string str ){
  stack <char> ch;
  int i;
  int len = str.size();
  for( i = 0; i < len; i++ ){
    if( !(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']' ))continue;
    if( str[i] == '(' || str[i] == '[') ch.push(str[i]);
    else {
     
      if( ch.empty() ){
	  return 0;
	}
    
      // if( ch.top() != '(' && str[i] == ')' ) return 0;
      else if( ch.top() == '(' && str[i] == ')' ) ch.pop();
      // else if( ch.top() != '[' && str[i] == ']' ) return 0;
      else if( ch.top() == '[' && str[i] == ']' ) ch.pop();

    }
  }
    
  if( !( ch.empty() ) ) return 0;
  return 1;
}

int main(){
 
  string str;
  while( getline(cin,str) ){
    if( str == "." ) break;
    if( check(str) == 1 ) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
	
	while(1){
		string a;
		
		string ans = "yes";
		
		getline(cin,a);
		if(a==".") break;
		char st[100];
		int p=0;
		
		for(int i=0;a[i];i++){
			if(a[i]=='('){
				st[p]=')';
				p++;
			}else if(a[i]=='['){
				st[p]=']';
				p++;
			}
			if(a[i]==')'||a[i]==']'){
				p--;
				if(p<0){
					ans ="no";
					break;
				}
				if(st[p]!=a[i]){
					ans="no";
					break;
				}
			}
		}
		if(p!=0)ans="no";
		
		cout << ans << endl;
		
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  char s[101];
  while(gets(s),s[0]!='.'){
    stack<char> a;
    int i=0;
    for(;s[i]!='.';++i){
      if(!(s[i]-'(')||!(s[i]-'['))a.push(s[i]);
      if(s[i]==')')if(a.empty()||a.top()!='(')break;else a.pop();
      if(s[i]==']')if(a.empty()||a.top()!='[')break;else a.pop();
    }cout<<(s[i]!='.'||!a.empty()?"no":"yes")<<endl;
  }
}

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

using namespace std;
typedef long long ll;

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

int main(void){
    string s;
    char bra[] = {'(', ')', '[', ']'};
    while(getline(cin, s) && s!=".") {
        stack<char> stk;
        bool ok = true;
        rep(i, s.size()) {
            bool is_bracket = false;
            rep(j, 4) if(s[i] == bra[j]) is_bracket = true;
            if(!is_bracket) continue;
            if(stk.empty() || s[i] == '(' || s[i] == '[') stk.push(s[i]);
            else if( (stk.top() == '(' && s[i] == ')') ||
                     (stk.top() == '[' && s[i] == ']') ) stk.pop();
            else {
                ok = false;
                break;
            }
        }

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