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;

int main() {
  bool flag = true;

  string str;
  //cout << "--------------" << endl;
  int i = 0;

  while(getline(cin, str)) {
    bool already_cout = false;
    // cout << str << "===============" << endl;
    //cout << i << endl;
    if (str == ".") {
      // cout << "brak" << endl;
      break;
    }
    stack<char> S;
    bool total_ok = true;
    for (int i = 0; i < str.size(); i ++) {
      if (str[i] == '(' || str[i] == '[' || str[i] == ')' || str[i] == ']') {
        // cout << i << "," << str[i] <<endl;
      }

      // 左括弧
      if (str[i] == '(' || str[i] == '[') {
        S.push(str[i]);
      }
      // 右括弧
      else if (str[i] == ')') {
        bool is_ok = true;
        if (S.empty()) {
          is_ok = false;
          total_ok = false;
        } else {
          if (S.top() == '(') {

            S.pop();
          } else {
            is_ok = false;
            total_ok = false;
            already_cout = true;
            // cout << "kokode no, " << S.top() << "," << i << endl;
            cout << "no" << endl;
            break;
          }
        }
      }
      else if (str[i] == ']') {
        bool is_ok = false;

        if (S.empty()) {
          if (i >= 99) {
            // cout << "koko kitayo 1" << endl;
          }
          is_ok = false;
          total_ok = false;
        } else {
          if (S.top() == '[') {
            if (i >= 99) {
              // cout << "koko kitayo 2" << "," << i << endl;
            }
            S.pop();
          } else {
            if (i >= 99) {
              // cout << "koko kitayo 3" <<  "," << i << endl;
            }
            is_ok = false;
            total_ok = false;
            already_cout = true;
            // cout << "kokode no 2" << endl;
            cout << "no" << endl;
            break;
          }
        }
      }
    }
    if (!S.empty()) {
      // cout << "dame" << endl;
      total_ok = false;
    }
    if (total_ok) {
      cout << "yes" << endl;
    } else if (!already_cout) {
      cout << "no" << endl;
    }
  }
}

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

int main(){
    string S;
    while(true){
        getline(cin,S);
        if(S==".") break;
        stack<char> st;
        bool yes = true;
        for(auto c:S){
            if(c=='(' || c=='[') st.push(c);
            if(c==')'){
                if(st.empty()) yes = false;
                else if(st.top()=='(') st.pop();
                else yes = false;
            }
            if(c==']'){
                if(st.empty()) yes = false;
                else if(st.top()=='[') st.pop();
                else yes = false;
            }
        }
        if(!st.empty()) yes = false;
        cout << (yes? "yes":"no") << endl;
    }
}

C++: #include <stdio.h>
#include <string.h>
#include <stack>
using namespace std;
char s[200];
stack <char> ss;
int main()
{
    while (fgets(s,150,stdin))
    {
        int len=strlen(s);
        s[len-1]=0;
        if (strcmp(s,".")==0) break;
        len--;
        while (!ss.empty()) ss.pop();
        bool ok=true;
        for (int i=0;i<len;i++)
        {
            if (s[i]=='(') ss.push('(');
            else if (s[i]=='[') ss.push('[');
            else if (s[i]==')')
            {
                if (ss.empty()||ss.top()!='(')
                {
                    ok=false;
                    break;
                }
                ss.pop();
            }
            else if (s[i]==']')
            {
                if (ss.empty()||ss.top()!='[')
                {
                    ok=false;
                    break;
                }
                ss.pop();
            }
        }
        if (ok)
            if (!ss.empty()) ok=false;
        if (ok) puts("yes");
        else puts("no");
    }
    return 0;
}

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

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

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

using namespace std;

int main()
{
	string s;
	int stack[103]={0};
	int pointer=0;
	bool flag=true;

	getline(cin,s);
	while (s!=".")
	{
		for (int i=0;i<s.length();++i)
		{
			if (s[i]=='(') stack[pointer++] = 1;
			if (s[i]=='[') stack[pointer++] = 2;
			if ((s[i]==')')&&(stack[--pointer]!=1)) {flag=false; break;}
			if ((s[i]==']')&&(stack[--pointer]!=2)) {flag=false; break;}
		}

		if (flag&&pointer==0) cout<<"yes"<<endl;
		else cout<<"no"<<endl;

		flag = true;
		pointer = 0;
		getline(cin,s);
	}
}