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>
using namespace std;

const int MAX_LENGTH = 1 << 10;

bool isYes(char input[]);

int main()
{
	char Input[MAX_LENGTH];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		if(Input[0] == '.') break;
		if(isYes(Input)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	enum __FLAG{NONE, PARE, BLAC};
	int prep[MAX_LENGTH], prepnum=0, p=NONE;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=PARE;
		} else if(Input[i] == '['){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=BLAC;
		} else if(Input[i] == ')'){
			if(p!=PARE){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=BLAC){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return p==NONE;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	string s;
	while(1)
	{
		getline(cin,s);
		if(s==".")break;
		stack<string> st;
		int len=s.size();
		for(int i=0;i<len;i++)
		{
			string tmp;
			tmp+=s[i];
			if(s[i]=='('||s[i]=='[')st.push(tmp);
			if(s[i]==')')
			{
				if(st.empty())
				{
					cout << "no" << endl;
					goto end;
				}
				string p=st.top();
				st.pop();
				if(p!="(")
				{
					cout << "no" << endl;
					goto end;
				}
			}
			if(s[i]==']')
			{
				if(st.empty())
				{
					cout << "no" << endl;
					goto end;
				}
				string p=st.top();
				st.pop();
				if(p!="[")
				{
					cout << "no" << endl;
					goto end;
				}
			}
		}
		if(!st.empty())
		{
			cout << "no" << endl;
			goto end;
		}
		cout << "yes" << endl;
		end:;
	}
	return 0;
}

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

using namespace std;

char s[1000];

string solve()
{
	stack<char> st;

	for(int i = 0; s[i] != '.'; i++)
	{
		if( s[i] == '(' )
		{
			st.push('(');
		}
		else if( s[i] == '[' )
		{
			st.push('[');
		}
		else if( s[i] == ')' )
		{
			if( !st.empty() && st.top() == '(' )
				st.pop();
			else
				st.push(')');
		}
		else if( s[i] == ']' )
		{
			if( !st.empty() && st.top() == '[' )
				st.pop();
			else
				st.push(']');
		}
	}

	if( st.empty() && st.empty() )
		return "yes";
	else 
		return "no";
}

int main()
{
	while( cin.getline(s,sizeof(s)), s[0] != '.' )
		cout << solve() << endl;

	return 0;
}

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

int main(){
  vector < char > moji;
  string str;
  int i;
  while(getline(cin,str)){
    int flag = 0;
    int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
    if( str == "." ) break;
    
    int len = str.size();

    moji.clear();
      
    for( i = 0; i < len; i++ ){
      if( str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']'){
	if( str[i] == '(' ) cnt1++;
	if( str[i] == ')' ) cnt2++;
	if( str[i] == '[' ) cnt3++;
	if( str[i] == ']' ) cnt4++;

	moji.push_back(str[i]);
      }
    }
   
    if( cnt1 != cnt2 ) flag = 1;
    if( cnt3 != cnt4 ) flag = 1;
    
    int len2 = moji.size();
        
    for( i = 0; i < len2-1; i++ ){
      if( moji[0] == ')' ) flag = 1;
      if( moji[0] == ']' ) flag = 1;
      
      if( moji[i] == '[' && moji[i+1] == ')' ) flag = 1;
      if( moji[i] == '(' && moji[i+1] == ']' ) flag = 1;
    }

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

  }
  return 0;
}

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

int main()
{
	string str;
	while (getline(cin, str), str != '.'){
		int c = 0, s = 0, f = 0;
		bool res = false;
		for (int p = 0; p < str.size(); p++){
			if (str[p] == '('){
				f = 1;
				c++;
			}
			else if (str[p] == ')'){
				if (f == 2) break;
				f = 0;
				c--;
			}
			else if (str[p] == '['){
				f = 2;
				s++;
			}
			else if (str[p] == ']'){
				if (f == 1) break;
				f = 0;
				s--;
			}
			if (c < 0 || s < 0) break;
			if (p == str.size() - 1) res = true;
		}
		if (res && !c && !s) puts("yes");
		else puts("no");
	}
	
	return 0;
}

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

using namespace std;



int main() {
	string str;
	
	while (getline(cin, str)) {
		if ((int)str.size() == 1 && str[0] == '.') break;
		int n = (int)str.size();
		
		stack<char> s;
		
		bool isok = true;
		for (int i=0; i<n && isok; i++) {
			if (str[i] == '(') {
				s.push(str[i]);
			} else if (str[i] == ')') {
				if (s.empty()) {
					isok = false;
					break;
				}
				char popc = s.top(); s.pop();
				if (popc != '(') isok = false;
			} else if (str[i] == '[') {
				s.push(str[i]);
			} else if (str[i] == ']') {
				if (s.empty()) {
					isok = false;
					break;
				}
				char popc = s.top(); s.pop();
				if (popc != '[') isok = false;
			}
		}
		
		if (isok) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

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

using namespace std;

int main(){
    string s;
    while(getline(cin,s)){
        if(s==".")break;
        stack<char>st;
        for(auto x:s){
            if(x=='(')st.push(x);
            if(x=='[')st.push(x);
            if(x==')'){
                if(!st.empty() && st.top()=='(')st.pop();
                else{
                    st.push(x);
                    break;
                }
            }
            if(x==']'){
                if(!st.empty() && st.top()=='[')st.pop();
                else{
                    st.push(x);
                    break;
                }
            }
        }
        if(st.empty())cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}