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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;
	while(1){
	  cin >> hoge[i];
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
	  }else if(hoge[a]==')'){
		mini--;
	  }else if(hoge[a]=='{'){
		big++;
	  }else if(hoge[a]=='}'){
		big--;
	  }
	}
	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

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;
		if (yes == true){
//			cout << "yes" << endl;
			fout << "yes" << endl;
		}
		else{
//			cout << "no" << endl;
			fout << "no" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void test(int );
int f,count,count1;
char ch[101]; 
int main(){
  while(1){
    int j=0;
    while(1){
      scanf("%c",&ch[j]);
      if(ch[j]=='.')break;
      j++; 
    }
    if(j==0)break;
    count=0,count1=0;

    for(int i=0;i<j;i++){
      if(ch[i]=='[')count++;
      else if(ch[i]=='(')count1++;
      else if(ch[i]==']' || ch[i]==')')test(i);
      if(count1<0||count<0||f==1)break; 
    }

    if(count==0&&count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char a;
    scanf("%c",&a);
  }
  return 0;
}

void test(int x){
  f=0;
  int k;
  int count2=0;
  if(ch[x]==')'){
    count1--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='('){
	for(int j=x-1;j>i;j--)
	  if(ch[j]=='[')count2++;
	  else if(ch[j]==']')count2--;
	break;
      }
  }
  else if(ch[x]==']'){
    count--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='['){
	for(int j=x-1;j>i;j--)
	  if(ch[j]=='(')count2++;
	  else if(ch[j]==')')count2--;
	break;
      }
  }
  if(count2>=1)f=1;
}

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

int main(){
  char s[256],c ;
  string st;
  int len, i;
  stack<char> stack;

  while( true ){
    fgets( s,255,stdin );
    st = s;
    len = st.length();
    if( st[len-1]=='\n' ) st[--len]='\0';

    if( len==1 && st[0]=='.' ) break;
    //    cout << st << endl;

    while( !stack.empty() ) stack.pop();

    for( i=0;i<len;i++ ){
      c = st.at(i);
      switch( c ){
      case '(':
      case'[': stack.push( c ); break;
      case ')':
	if( stack.empty() ){
	  stack.push( c );	  i=len;
	}else{
	  if( stack.top()=='(' ) stack.pop();
	  else i=len;
	}
	break;
      case ']':
	if( stack.empty() ){
	  stack.push( c );	  i=len;
	}else{
	  if( stack.top()=='[' ) stack.pop();
	  else i=len;
	}
	break;
      default :
	break;
      }
    }

    if( stack.empty() ) cout << "yes"<<endl;
    else         cout << "no"<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    string str,ans=")]";
    while(getline(cin,str)&&str!="."){
        stack<int> sta;
        for(int i=0;i<str.size();i++){
            if(str[i]=='(')sta.push(0);
            if(str[i]=='[')sta.push(1);
            if((str[i]==')'||str[i]==']')&&!sta.empty()&&str[i]==ans[sta.top()])sta.pop();
            else if(str[i]==')'||str[i]==']'){
                sta.push(0);
                break;
            }
        }
        if(sta.empty())cout<<"yes\n";
        else cout<<"no\n";
    }
}

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.length();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 <string>

using namespace std;

const string Terminater = ".";

bool isOK(string& str)
{
	stack<char> st;
	for (char& c : str)
	{
		if (c == '(' || c == '[')
			st.push(c);

		if (c == ')')
		{

			if ( !st.empty() && '(' == st.top())
				st.pop();
			else
				return false;
		}
		else if (c == ']')
		{
			if (!st.empty() && '[' == st.top())
				st.pop();
			else
				return false;
		}
	}

	if (st.empty())
		return true;

	return false;
}

int main()
{
	while (1)
	{
		string str;
		cin >> str;

		if (str == Terminater)
			break;

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

C++: #include <iostream>
using namespace std;
int main(){
	char buf[110],stack[110]={0},*sp,*p;
	while(fgets(buf,103, stdin),*buf!='.'){
		sp=stack+1;
		p=buf;
		for(;*p!='.';p++){
			if(*p == '(' || *p == '['){
				*sp++ = *p;
			}else if(*p == ')' || *p == ']'){
				sp--;
				if(!((*sp =='(' && *p == ')') || (*sp =='[' && *p == ']'))){
					puts("no");
					break;
				}
			}
		}
		if(*p=='.')puts(sp==stack+1?"yes":"no");
	}
}