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>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int ro,so,i,j,k,b[51]={},p=0;
  while(str.size()!=1||str[0]!='.'){
    ro=0;so=0;k=0;p=0;
    for(i=0;i<str.size();i++){
      if(str[i]=='(') {
	ro++;
	p++;
	b[p]=1;
      }
      if(str[i]=='[') {
	so++;
	p++;
	b[p]=2;
      }	  
      if(str[i]==')') {
	if(b[p]==1) {
	  ro--;
	  p--;
	}
	else k=1;
      }
      if(str[i]==']') {
	if(b[p]==2) {
	  so--;
	  p--;
	}
	else k=1;
      }

      if(ro<0||so<0) k=1;
    }
    if(k==0&&ro==0&&so==0) cout << "yes" << endl;
    else cout << "no" << endl;
    getline(cin,str);
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int search(int i, char c);

char str[200];
int l;

int main()
{
	while(1){
		fgets(str, sizeof(str), stdin);
		if(str[0] == '.') break;
		int ans = 1;
		l = strlen(str);
		for(int i = 0; i < l; i++){
			if(str[i] == '(' || str[i] == '['){
				ans = search(i, str[i]);
				break;
			} else if(str[i] == ')' || str[i] == ']'){
				ans = 0;
				break;
			}
		}
		if(ans == 1) cout << "yes" << endl;
		else if(ans == 0) cout << "no"<< endl;
	}
	return 0;
}

int search(int i, char c)
{
	if(i == l-1) return 0;
	char d, e;
	if(c == '('){
		d = ')';
		e = ']';
		}else if(c == '['){
			d = ']';
			e = ')';
		}
	for(int j = i+1; j < l; j++){
		if(str[j] == '(' || str[j] == '['){
			return search(j, str[j]);
		} else if(str[j] == d){
			str[j] = '0';
			return 1;
		} else if(str[j] == e){
			return 0;
		}
	}
	return 0;
}

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

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

int main() {
  string query;
  while (getline(cin, query) and query != ".") {
    cout << (solve(query) ? "yes" : "no" ) << endl;
  }
}

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

using namespace std;

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

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

using namespace std;

int main(){
	int maru=0,kaku=0;

	string str;
	while(getline(cin,str)){
		if(str.at(0)=='.')break;
		maru=0;
		kaku=0;
		int flag=0;
		stack<int> s;

		for(int i=0;i<str.size();i++){
			if(str.at(i)=='('){
				maru++;
				s.push(1);
			}
			else if(str.at(i)==')' && maru>0){
				if(s.top()==1){
					maru--;
					s.pop();
				}
				else{
					cout<<"no"<<endl;
					flag=1;
				}
			}
			if(str.at(i)=='['){
				kaku++;
				s.push(2);
			}
			else if(str.at(i) ==']' &&kaku>0){
				if(s.top()==2){
					kaku--;
					s.pop();
				}
				else{
					cout<<"no"<<endl;
					flag=1;
				}
			}
			if(flag==1)break;
		}
		if(flag==1)continue;

		if(maru==0&&kaku==0&&flag==0){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}

	return 0;
}

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

#define MAX (1000)

int main(void)
{
	int sp;
	char stack[MAX];
	char str[MAX + 1];
	while (1){
		int i;

		fgets(str, MAX, stdin);
		if (str[0] == '.'){
			break;
		}

		sp = 0;
		for (i = 0; str[i] != '\n'; i++){
			if (str[i] == '[' || str[i] == '('){
				stack[sp++] = str[i];
			}
			else if (str[i] == ')' || str[i] == ']'){
				if (sp == 0){
					break;
				}
				char top = stack[--sp];
				if (top == '['){
					top = ']';
				}
				else {
					top = ')';
				}
				if (top != str[i]){
					break;
				}
			}
		}
	
		
		if (i != 0 && str[i] == '\n' && str[i - 1] == '.'){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='[' || s[i]=='(' || s[i]==']' || s[i]==')')ch+=s[i];

    for(int i=0;i<ch.length();i++){
      
      if(ch[i]=='(' || ch[i]=='[')str.push(s[i]);
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]==']' && str.top()=='[')str.pop();
    }

    cout << (str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>
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;
}