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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	string str;
	stack<int> st;

	

	while(getline(cin, str) && str != ".") {
		bool successed = true;
		st.push(2);

		FOR(i, 0, str.size()) {
			char c = str[i];

			if(c == '(') {
				st.push(0);
			} else if(c == '[') {
				st.push(1);
			} else if(c == ')') {
				if(st.top() != 0) {
					successed = false;
					break;
				}
				st.pop();
			} else if(c == ']') {
				if(st.top() != 1) {
					successed = false;
					break;
				}
				st.pop();
			}
		}

		if(successed) {
			if(st.top() == 2) {
				cout << "yes" << endl;
			} else {
				cout << "no" << endl;
			}
		} else {
			cout << "no" << endl;
		}

	}

	return 0;
}

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

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

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		if(str == ".")
		{
			break;
		}
		stack<char> Stack;
		bool flag = true;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == '(' || str[i] == '[')
			{
				Stack.push(str[i]);
			}
			else if(str[i] == ')')
			{
				if(Stack.empty() || Stack.top() != '(')
				{
					flag = false;
					break;
				}
				else
				{
					Stack.pop();
				}
			}
			else if(str[i] == ']')
			{
				if(Stack.empty() || Stack.top() != '[')
				{
					flag = false;
					break;
				}
				else
				{
					Stack.pop();
				}
			}
		}
		if(flag && !Stack.empty())
		{
			flag = false;
		}
        
        if(flag)
		{
			cout << "yes" << endl;
		}
        else
		{
			cout << "no" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

int main() {
    while(true) {
        string line; getline(cin, line);
        if(line == ".") break;
        stack<char> s;
        bool valid = true;
        for(int i = 0; i < (int)line.length(); i++) {
            char c = line[i];
            if(c == '(' || c == '[') s.push(c);
            else if(c == ')') {
                if(s.empty() || s.top() != '(') valid = false;
                else s.pop();
            }
            else if(c == ']') {
                if(s.empty() || s.top() != '[') valid = false;
                else s.pop();
            }
        }
        cout << (valid ? "yes" : "no") << endl;
    }
}

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

using namespace std;
int main(){
	string str;
	while(getline(cin,str)&& str!="."){
		stack<char> s;
		bool f=true;
		string ss;

		for(int i=0;i<str.size();i++){
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				ss+=str[i];
		}

		for(int i=0;i<ss.size();i++){
			if(ss.empty() || ss[i]=='(' || ss[i]=='[')
				s.push(ss[i]);

			else{
				if( (s.top()=='(' && ss[i]==')') || (s.top()=='[' && ss[i]==']') ){
					s.pop();
				}
				else{
					f=false;
					break;
				}
			}
		}
		if(f)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}