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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

bool solve(string s)
{
	stack<char> st;
	rep(i,s.size()){
		if(s[i]=='(' || s[i]=='[')
			st.push(s[i]);
		if(s[i]==')' || s[i]==']'){
			if(st.empty())
				return false;
			else if(s[i]==')' && st.top()!='(')
				return false;
			else if(s[i]==']' && st.top()!='[')
				return false;
			else
				st.pop();
		}
	}
	return st.empty();
}

int main()
{
	for(string s;getline(cin,s),s!=".";)
		puts(solve(s)?"yes":"no");
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void){
	for(char c; c = getchar(), c != '.';){
		string res = "yes";
		stack<char> stk;
		do {
			if(c == '(' || c == '[') stk.push(c);

			if(c == ')'){
                if(stk.empty() || stk.top() != '(') res = "no";
                else stk.pop();
            }
			if(c == ']'){
                if(stk.empty() || stk.top() != '[') res = "no";
                else stk.pop();
            }
		} while(c = getchar(), c != '.');
        if(stk.size()) res = "no";

        cout << res << endl;
        c = getchar();
	}

	return 0;
}

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

int main(){
  string str; 
  while(1){
    int a=0;
    while(1){
      cin>>str;
      if(str==".")break;
    }
    if(str[0]=='.')break;
    a=str.size();
    int count=0,count1=0;
    for(int i=0;i<a;i++){
      if(str[i]=='[') count++; 
      else if(str[i]=='{')count1++;
      else if(str[i]=='}')count1--;
      else if(str[i]==']')count--;
    }  
    if(count==0 && count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
  } 
  return 0;
}

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

int main()
{
	string line;
	while (getline(cin,line) && line != ".")
	{
		stack<char> st;
		bool flag = true;
		for (int i = 0; i < line.size(); i++)
		{
			char c = line.at(i);
			if ((c == ']' || c == ')') && st.size() < 1)
			{
				flag = false;
				break;
			}
			if (c == ']')
			{
				if (st.top() == '[')
				{
					st.pop();
				}
				else
				{
					flag = false;
					break;
				}
			}
			else if (c == ')')
			{
				if (st.top() == '(')
				{
					st.pop();
				}
				else
				{
					flag = false;
					break;
				}
			}
			else if (c == '[')
			{
				st.push(c);
			}
			else if (c == '(')
			{
				st.push(c);
			}
		}

		if (st.size() > 0)flag = false;

		if (flag)
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
	return 0;
}

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

int main() {
  string s;
  while(getline(cin, s)) {
    if(s[0] == '.') break;

    bool b = true;
    stack<char> sta;
    for(int i = 0; i < s.size(); i++) {
      char c = s[i];
      if((c == ')' || c == ']') && sta.empty()) {
	b = false;
	break;
      }

      if(c == '(' || c == '[') {
	sta.push(c);
      }
      else if(c == ')' || c == ']') {
	if(c == ')' && sta.top() != '(') b = false;
	if(c == ']' && sta.top() != '[') b = false;
	sta.pop();
      }
    }
    if(b) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <stack>
using namespace std;
int kakko(int ,string);
int main(){
  int n ,shou=0 ,chu=0;
  string s;
  while( 1 ){
    getline(cin ,s);
    n = s.size();
    if( s[0] == '.' ){
      break;
    }
    kakko(n ,s);
  }
}


int kakko(int n ,string s){
  int shou=0 ,chu=0 ,flag=0;
  stack<int> jun; // 括弧の順番を調べる
  jun.push(0);
  for( int i=0 ; i<n ; i++ ){
    switch(s[i]){ // ( ,[の数を求める
    case '(':
      shou++;
      jun.push(1); // 入った順を記憶
      break;
      
    case '[':
      chu++;
      jun.push(2); // 入った順を記憶
      break;
      
    case ')':
      if( jun.top() == 1 || jun.top() == 0 ){ // 順どおりなら
	shou--;
	jun.pop();
      }
      else{
	flag = 1;
      }
      break;
      
    case ']':
      if( jun.top() == 2 || jun.top() == 0 ){ // 順どおりなら
	chu--;
	jun.pop();
      }
      else{
	flag = 1;
      }
      break;
      
    default:
      continue;
      break;
    }
    
    if( shou < 0 || chu < 0 || flag == 1 ){ 
      cout << "no" << endl;
      return 0;
    }
  }
  
  if( shou == 0 && chu == 0 ){ // 対応してたら
    cout << "yes" << endl;
  }
  else{ // 対応してなかったら
      cout << "no" << endl;
  }
  return 0;
}

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

#define MAX (1000)

int main(void)
{
	int sp;
	char stack[MAX];
	char str[MAX + 1];
	while (1){
		int i;

		fgets(str, MAX, stdin);
		if (str[0] == '.'){
			break;
		}

		if (str[strlen(str) - 1] == '\n'){
			str[strlen(str) - 1] = '\0';
		}

		sp = 0;
		for (i = 0; str[i] != '\0'; i++){
			if (str[i] == '[' || str[i] == '('){
				stack[sp++] = str[i];
			}
			else if (str[i] == ')' || str[i] == ']'){
				if (sp == 0){
					break;
				}
				char top = stack[--sp];
				if (top == '['){
					top = ']';
				}
				else {
					top = ')';
				}
				if (top != str[i]){
					break;
				}
			}
		}
	
		
		if (i != 0 && str[i] == '\0' && str[i - 1] == '.'){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}