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"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] == ')'){
				if (!s.empty()){
					if (s.top() == '('){
						yes = true;
						s.pop();
					}
					else {
						yes = false;
						break;
					}
				}
				else {
					yes = false;
					break;
				}
			}
			if (a[i] == ']'){
				if (!s.empty()){
					if (s.top() == '['){
						yes = true;
						s.pop();
					}
					else {
						yes = false;
						break;
					}
				}
				else {
					yes = false;
					break;
				}
			}
			//			if (!s.empty())
			//				cout << a[i] << "  :  " << s.top() << "  :  " << yes << endl;
			//			else cout << "topエラー" << endl;
			if (a[i] == '.')break;
		}
		if (!s.empty())yes = false;
		while (!s.empty())s.pop();
		if (yes == true){
//			cout << "yes" << endl;
			fout << "yes" << endl;
		}
		else{
//			cout << "no" << endl;
			fout << "no" << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    string inp;

    while (getline(cin, inp), inp != ".") {

        stack<char> st;
        bool flag = true;

        for (int i = 0; i < inp.size(); i++) {
            if (inp[i] == '(' || inp[i] == '[') 
                st.push(inp[i]);
            else if (inp[i] == ')') {
                if (st.empty() || st.top() == '[') {
                    flag = false;
                    break;
                }
                else if (st.top() == '(')
                    st.pop();
            }
            else if (inp[i] == ']') {
                if (st.empty() || st.top() == '(') {
                    flag = false;
                    break;
                }
                else if (st.top() == '[')
                    st.pop();
            }
        }
        
        if (flag && st.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}

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

int main(){
	string s;
	while(getline(cin, s)) {
		if(s == ".") break;
		vector<int> v(2);
		vector<int> tmp[2];
		bool f = true;
		for(auto& c: s) {
			if(c == '(') {
				v[0]++;
				tmp[0].push_back(v[1]);
			}
			if(c == ')') {
				if(v[0] == 0 || tmp[0].back() != v[1]) {
					f = false;
					break;
				}
				else {
					v[0]--;
					tmp[0].pop_back();
				}
			}
			if(c == '[') {
				v[1]++;
				tmp[1].push_back(v[0]);
			}
			if(c == ']') {
				if(v[1] == 0 || tmp[1].back() != v[0]) {
					f = false;
					break;
				}
				else {
					v[1]--;
					tmp[1].pop_back();
				}
			}
		}
		if(v[0] != 0 || v[1] != 0) f = false;
		cout << (f ? "yes" : "no") << endl;
	}
}

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

using namespace std;

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

C++: #include <cstdio>
#include <iostream>
#include <deque>
#include <cstring>
using namespace std;
bool beginC(char c) {
	return (c == '[' || '(' == c);
}
bool endC(char c) {
	return (c == ']' || ')' == c);
}
bool cuple(char l, char r) {
	return (l == '(' && r == ')') || (l == '[' && r == ']');
}
int size;
bool solve(char str[]) {
	deque<char> deq;
	for (int i = 0; i < size; i++) {
		if (beginC(str[i])) {
			deq.push_front(str[i]);
		}
		else if (endC(str[i])) {
			if (deq.empty()) return false;
			char recent = deq.front();
			if (!cuple(recent, str[i])) {
				return false;
			}
			deq.pop_front();
		}
	}
	return deq.size() == 0;
}

int main() {
	char str_c[128];
	while (1) {
		cin.getline(str_c, 128);
		size = strlen(str_c);
		string str(str_c);
		if (str == ".") return 0;
		cout << (solve(str_c) ? "yes" : "no") <<endl;
	}
	return 0;
}

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

int main()
{
  string s;
  while(getline(cin,s)){
    stack<char> b;
    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;
          break;
        }
        b.pop();
      }else if(s[i] == ']'){
        if(b.empty() || b.top() != '['){
          cout << "no" << endl;
          break;
        }
        b.pop();
      }
    }
    if(b.empty())
      cout << "yes" << endl;
  }
}

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

bool isBalanced(string s){
	stack<char> acc;
	for(int unsigned i=0;i<s.size();i++){
		if(s[i] == '[') acc.push(']');
		if(s[i] == '(') acc.push(')');
		if(s[i] == ']' || s[i] == ')'){
			if(acc.empty()) return false;
			if(s[i] == acc.top()){
				acc.pop();
			} else {
				return false;
			}
		}
	}
	return acc.empty();
}

int main(){
	string s;
	string left("([");
	string right(")]");
	while(getline(cin,s),s!="."){
		stack<char> acc;
		if(isBalanced(s)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
	while(1){
		char input[128];
		int hmMaru = 0,hmKaku = 0;
		bool fAns = true;

		cin >> input;
		if(strcmp(input,".") == 0)
			break;

		for(int i = 0;i < strlen(input);i++)
		{
			bool fEnd = false;
			switch(input[i])
			{
				case '(':
					hmMaru++;
					break;
				case ')':
					hmMaru--;
					if(hmMaru != 0){
						fAns = false;
						fEnd = true;
					}
					break;
				case '[':
					hmKaku++;
					break;
				case ']':
					hmKaku--;
					if(hmKaku != 0){
						fAns = false;
						fEnd = true;
					}
					break;
				case '.':
					fEnd = true;
					break;
			}
			if(fEnd == true){
				if(fAns == true){
					cout << "yes" << endl;
				}else{
					cout << "no" << endl;
				}
			}
		}
	}
}