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 <vector>
#include <queue>
#include <memory.h>
#include <functional>
#include <algorithm>
using namespace std;
#include <stack>

//FILE * in = freopen("input.txt", "r" , stdin);
char data[1000];

int main() {
	
	while(true) {
		bool flag = false;
		gets(data);
		if(data[0] == '.' && data[1] == 0)break;
		int i = 0;
		stack<int> a;
		while(data[i] != '.'){
			switch(data[i])
			{
			case '(':
				a.push('(');
				break;
			case '[':
				a.push('[');
				break;
			case ')':
				if(a.empty()) {
					flag = true;
					goto out;
				}
				if(a.top() == '(')
					a.pop();
				else {
					flag = true;
					goto out;
				}
				break;

			case ']':
				if(a.empty()) {
					flag = true;
					goto out;
				}
				if(a.top() == '[')
					a.pop();
				else {
					flag = true;
					goto out;
				}
				break;
			default:
				break;
			}
			i++;
		}
		out:
		if(!flag && a.empty())
			puts("yes");
		else
			puts("no");
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>
#include<stack>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005

int main(){

    while(true){
        string s;
        getline(cin,s);
        if(s == "."){
            break;
        }
        stack<char> stk;
        bool exist = true;
        REP(i,s.size()){

            if(s[i] == '('){
                stk.push('(');
            }
            if(s[i] == '['){
                stk.push('[');
            }
            if(s[i] == ')'){
                if(stk.empty() || stk.top() != '('){
                    //空か(がないか
                    exist = false;
                    break;
                }else{
                    stk.pop();
                }
            }
             if(s[i] == ']'){
                if(stk.empty() || stk.top() != '['){
                    //空か[がないか
                    exist = false;
                    break;
                }else{
                    stk.pop();
                }
            }
        }
        if(exist && stk.empty()){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

  


    return 0;
}

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


#define INPUT_MAX 101
#define KAKKO_MAX 48

using namespace std;

int main(void)
{
	int countMaru = 0;
	int countKaku = 0;
	int idx = 0;
	string stack(KAKKO_MAX, '\0');
	string dataset(INPUT_MAX, '\0');
	
	while(getline( cin, dataset))
	{
		if(dataset[0] == '.')
		{
			break;
		}
		for(int i = 0; i < INPUT_MAX; i++)
		{
			if(dataset[i] == '.')
			{
				if((countMaru == 0) && (countKaku == 0))
				{
					cout << "yes\n";
					break;
				}
				else
				{
					cout << "no\n";
					break;
				}
			}
			else if(dataset[i] == '(')
			{
				countMaru++;
				stack[idx] = '(';
				idx++;
			}
			else if(dataset[i] == '[')
			{
				countKaku++;
				stack[idx] = '[';
				idx++;
			}
			else if(dataset[i] == ')')
			{
				if(idx == 0)
				{
					cout << "no\n";
					break;
				}
				else if(stack[idx-1] == '[')
				{
					cout << "no\n";
					break;
				}
				else
				{
					idx--;
					stack[idx] = '\0';
					countMaru--;
				}
			}
			else if(dataset[i] == ']')
			{
				if(idx == 0)
				{
					cout << "no\n";
					break;
				}
				else if(stack[idx-1] == '(')
				{
					cout << "no\n";
					break;
				}
				else
				{
					idx--;
					stack[idx] = '\0';
					countKaku--;
				}
			}
			else
			{
				// 処理なし
			}
		}
		
		idx = 0;
		countMaru = 0;
		countKaku = 0;
	}
	
	return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

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

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

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

C++: // AOJ 1173

#include <iostream>
#include <string>
#include <stack>
using namespace std;

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