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

bool check(string str){
  stack<char> par;
  for(char c : str) {
    if(c == '(' or c == '[') {
      par.push(c);
    }else if(c == ')') {
      if(par.empty() or par.top() != '(') {
	return false;
      }
      par.pop();
    }else if(c == ']'){
      if(par.empty() or par.top() != '[') {
	return false;
      }
      par.pop();
    }
  }

  return par.empty();
}

int main() {
  string str;
  while(true) {
    getline(cin, str);
    if(str == ".") break;

    if(check(str)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

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

using namespace std;

int main(){
  int i, isCorrect;
  string str, _str;

  while(1){
    getline(cin, str);
    if(str == ".") break;

    for(i=0, isCorrect=1; i<str.size(); ++i){
      if(str[i] == '(' || str[i] == '['){
	_str.push_back(str[i]);
      }else if(str[i] == ')'){
	if(_str.size() == 0 || _str[_str.size()-1] != '(')
	  isCorrect = 0;
	else
	  _str.erase(_str.end()-1);
      }else if(str[i] == ']'){
	if(_str.size() == 0 || _str[_str.size()-1] != '[')
	  isCorrect = 0;
	else
	  _str.erase(_str.end()-1);
      }

      if(isCorrect == 0) break;
    }

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

    str.clear();
    _str.clear();
  }

  return 0;
}

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

pair<bool, int> square(string s, int i);

pair<bool, int> rounded(string s, int i){
    pair<bool, int> ret;
    for(;i<s.length();++i){
        if(s[i] == '['){
            ret = square(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }else if(s[i] == ']'){
            return (pair<bool, int>){false, i};
        }else if(s[i] == ')'){
            return (pair<bool, int>){true, i};
        }else if(s[i] == '('){
            ret = rounded(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
    }
    return (pair<bool, int>){false, i};
}

pair<bool, int> square(string s, int i){
    pair<bool, int> ret;
    for(;i<s.length();++i){
        if(s[i] == '('){
            ret = rounded(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
        else if(s[i] == ')'){
            return (pair<bool, int>){false, i};
        }else if(s[i] == ']'){
            return (pair<bool, int>){true, i};
        }else if(s[i] == '['){
            ret = square(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
    }
    return (pair<bool, int>){false, i};
}

int main(){
    string s;
    while(getline(cin,s), s[0] != '.'){
        bool flag = false;
        pair<bool, int> ret = pair<bool, int>{true, 0};
        for(int i=0;i<s.length();++i){
            if(s[i] == '('){
                ret = rounded(s, i+1);
                if(ret.first == false){
                    flag = true;
                    printf("no\n");
                    break;
                }
                i = ret.second;
            }else if(s[i] == '['){
                ret = square(s, i+1);
                if(ret.first == false){
                    flag = true;
                    printf("no\n");
                    break;
                }
                i = ret.second;
            }else if(s[i] == ')' || s[i] == ']'){
                printf("no\n");
                flag = true;
                break;
            }
        }
        if(flag == false && ret.first == true)printf("yes\n");
        else if(flag == false)printf("no\n");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>

using namespace std;

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

	return 0;
}

C++: #include"iostream"
#include"fstream"
#include"stack"
#include"string"

using namespace std;

int main(){

	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
	
	ifstream fin;
	ofstream fout;

	fin.open("input.txt");
	fout.open("output.txt");

	//http://www.cppll.jp/cppreference/cppstack_details.html
	//empty()関数は現在のスタックが空の時にtrueを返し、そうでないときはfalseを返す 

	string a;

	stack<char> s;
	bool yes = true;

	while (true){
		yes = true;

		getline(cin, a);

		//		cout << a << endl;

		//		if (a[0] == ' ')
		//			cout << "ファーーーwww" << endl;
		if (a[0] == '.')break;


		for (int i = 0; i < 100; i++){
			if (a[i] == '(' || a[i] == '['){
				s.push(a[i]);
				yes = false;
			}
			if (a[i] == ')' && !s.empty()){
				if (s.top() == '('){
					yes = true;
					s.pop();
				}
				else break;
			}
			if (a[i] == ']' && !s.empty()){
				if (s.top() == '['){
					yes = true;
					s.pop();
				}
				else break;
			}
			//			if (!s.empty())
			//				cout << a[i] << "  :  " << s.top() << "  :  " << yes << endl;
			//			else cout << "topエラー" << endl;

			if (a[i] == '.')break;
		}

		if (yes == true){
			//			cout << "yes" << endl;
			fout << "yes" << endl;
		}
		else{
			//			cout << "no" << endl;
			fout << "no" << endl;
		}
		while (!s.empty())s.pop();
	}
	return 0;
}