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 <string>
#include <algorithm>
#include <stack>

using namespace std;

int main()
{
  int end;
  stack <char> sta;

  while(1){
    string v;
    string l;
    string g;
    end = 0;

    while(1){
      cin>>v;
      l = l+v;

      for(auto s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

    if(l == "."){
      break;
    }

    for(auto e : l){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        auto t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        auto t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }

    if(g != "no"){
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

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

using namespace std;

int main(void)
{
	char c;

	while(1){
		cin.get(c);
		if(c=='.') break;
			
		stack<char> s;
		if(c=='(' || c=='[') s.push(c);
		else if(c==')' || c==']') s.push(c);

		while(1){
			cin.get(c);
			if(c=='.') break;

			if(c=='(' || c=='[') s.push(c);
			else if(c==')' && !s.empty() && s.top()=='(') s.pop();
			else if(c==']' && !s.empty() && s.top()=='[') s.pop();
		}
		cin.get(c);
		if(s.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), s != ".") {

        bool find = true;
        string world = "";

        for(int i = 0; i < s.size(); ++i) {
            switch(s[i]) {
                case '(':
                case ')':
                case '[':
                case ']':
                    world += s[i];
            }
        }

        while(find) {

            find = false;

            int balance;

            if((balance = world.find("()")) != string::npos) {
                world.erase(balance, 2);
                find = true;
            }
            if((balance = world.find("[]")) != string::npos) {
                world.erase(balance, 2);
                find = true;
            }

        }

        cout << (world.size() ? "no" : "yes") << endl;

    }

}

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

const char a[] = {'(', '['};
const char b[] = {')', ']'};

int main () {
    string str;
    while (getline(cin, str), str.size()) {
        stack<char> s;
        bool ans = true;
        for (int i = 0; i < str.size(); i++) {
            if ('a' > str[i] || str[i] > 'z') {
                if (str[i] == a[0] || str[i] == a[1]) {
                    s.push(str[i]);
                } else if (s.size() && str[i] == b[0] && s.top() == a[0]) {
                    s.pop();
                } else if (s.size() && str[i] == b[1] && s.top() == a[1]) {
                    s.pop();
                } else if (str[i] == b[0] || str[i] == b[1]) {
                    ans = false;
                    break;
                }
            }
        }
        if (s.size()) ans = false;

        cout << (ans ? "yes" : "no") << endl;
    }

    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	while(true) {
		string S; getline(cin, S);
		if(S == ".") break;
		stack<char> stk;
		bool ok = true;
		for(int i = 0; i < (int)S.size(); ++i) {
			if(S[i] == '[') {
				stk.push(S[i]);
			}
			if(S[i] == '(') {
				stk.push(S[i]);
			}
			if(S[i] == ']') {
				if(stk.empty() == false && stk.top() == '[') {
					stk.pop();
				}
				else {
					ok = false;
					break;
				}
			}
			if(S[i] == ')') {
				if(stk.empty() == false && stk.top() == '(') {
					stk.pop();
				}
				else {
					ok = false;
					break;
				}
			}
		}
		cout << (ok ? "yes" : "no") << endl;
	}
}

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

int main() {
  string s;
  while(getline(cin, s) && s != ".") {
    stack<char> sta;
    bool b = true;
    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 && sta.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <iostream>
#include <stack>
#include <vector>
#include <string>
using namespace std;
int main()
{
	string str;
	while( getline(cin,str) && str != "." ){
		string z;
		for(int i=0;i<str.size();i++)
			if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']')
				z+=str[i];
		stack<char> s;
		bool f = true;
		for(int  i=0;i < z.length();i++){
			if( z.empty() || z[i] == '(' || z[i] == '[' ){
				s.push(z[i]);
			}else if( (s.top() == '(' && z[i] == ')') || (s.top() == '[' && z[i] == ']') && ! s.empty() ){
				s.pop();
			}else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ? "yes": "no")  << endl;
	}

	return 0;
}

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	while(1){
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(1){
			if(letter[i] == '.') break;
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
			}
			}
			i++;
		}
		if(st.empty())
		cout << "yes" << endl;
		else
		cout << "no" << endl;
		for(int i = 0; i < st.size(); i++)
			st.pop();
	}
	return 0;
}

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

bool isPair(char top, char input) {
    if ((top == '(' && input ==')') 
        || (top == '[' && input ==']')) {
        return true;
    } 
    return false;
}

void check(string str) {
    stack<char> st;

    for (int i = 0; i < str.size(); ++i) {
        if (!st.empty()) {
            char top = st.top();
            if (isPair(top, str[i])) {
                st.pop();
                continue;
            }
        }
        
        if (str[i] == '(' || str[i] == ')' 
            || str[i] == '[' || str[i] == ']') {
            st.push(str[i]);
        }
    }

    if( st.empty() ) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}

int main() {
    string str;
    while(getline(cin, str), str.front() != '.') {
        cout<<str<<endl;
        check(str);
    }
    return 0;
}