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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int INF=1e9;

int main(){
	string s;
	while(getline(cin,s) and s!="."){
		cout<<s<<endl;
		string ans="yes";
		int n=s.size();
		stack<bool> last;
		rep(i,n){
			if(s[i]=='(') last.push(0);
			if(s[i]=='[') last.push(1);
			if(s[i]==')'){
				if(last.empty()) ans="no";
				else if(!last.top()) last.pop();
				else ans="no";
			}
			if(s[i]==']'){
				if(last.empty()) ans="no";
				else if(last.top()) last.pop();
				else ans="no";
			}
		}
		if(!last.empty()) ans="no";
		cout<<ans<<endl;
	}
    return 0;
}

C++: 

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}

int solve(string S) {
	int maru = 0, kaku = 0;
	Foreach(i, S) {
		if (i == '(') maru++;
		else if (i == '[') kaku++;
		else if (i == ')') {
			if (maru > 0) maru--;
			else {
				break;
			}
		}
		else if (i == ']') {
			if (kaku > 0)kaku--;
			else {
				break;
			}
		}
	}
	IfeOut(kaku == 0 && maru == 0, "yes", "no");
}

int main() {
	char S[105];
	while (cin.getline(S, sizeof(S)), S != ".")
	{
		solve(S);
	}
	return 0;
}

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

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

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

int main()
{
  string str;
  int i;
  while(true){
    getline(cin, str);
    if(str[0] == '.') break;
    
    int len = 0;
    while(str[len] != '\0'){
      len++;
    }
        
    int d[101] = {0}, j;
    for(i = 0, j = 0 ; i < len ; i++){
      if(str[i] == '('){
	d[++j] = 1;
      }
      if(str[i] == '['){
	d[++j] = 2;
      }
      if(str[i] == ')'){
	if(d[j--]-1){
	  break;
	}
      }
      if(str[i] == ']'){
	if(d[j--]-2){
	  break;
	}
      }
    }
    if(str[i] || j){
      cout << "no" << '\n';
    }else{
      cout << "yes" << '\n';
    }
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  string s;
  while(getline(cin,s), s!=".") {
    stack<char> stk;
    bool f = 1;
    REP(i,s.size()) {
      if (s[i]=='[' || s[i]=='(')
        stk.push(s[i]);
      if (s[i]==']') {
        if (stk.empty() || stk.top() != '[') {
          f = 0;
          break;
        } else
          stk.pop();
      } else if (s[i]==')') {
        if (stk.empty() || stk.top() != '(') {
          f = 0;
          break;
        } else
          stk.pop();
      }
    }
    if (f && stk.empty())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

C++: #include <stdio.h>



int main(void){
  char c, moji[101];
  int maru, kaku;
  bool end = true;
  bool dame;
  while(1){ 
    if(end){
      maru = 0;
      kaku = 0;
      dame = false;
    }
    end = false;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	moji[i] = '\0';
	break;
      }else{
	moji[i] = c;
      }
    }
    if(moji[0] == '.'){
      break;
    }
    for(int i=0; i<101; i++){
      if(moji[i] == '.'){
	end = true;
	break;
      }else if(moji[i] == '('){
	maru++;
      }else if(moji[i] == ')'){
	maru--;
	if(maru<0){
	  dame = true;
	}
      }else if(moji[i] == '['){
	kaku++;
      }else if(moji[i] == ']'){
	kaku--;
	if(kaku<0){
	  dame = true;
	}
      }else if(moji[i] == '\0'){
	break;
      }
    }
    if(end){
      if(maru == 0 && kaku == 0 && !dame){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}