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 <bits/stdc++.h>
using namespace std;

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        fgets(str, 104, stdin); 
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }else if(st.empty()){
                if(str[i]==')' || str[i]==']') judge = false;
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

C++: //
//  main.cpp
//  AOJ1173
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;

string S;
void solve(){
    int a = 0, b = 0;
    char last = '.';
    
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c == '('){
            last = c;
            a++;
        }else if(c == ')'){
            a--;
            if(last == '[' || a < 0){
                cout << "no" << endl;
                return;
            }
            last = c;
        }else if(c == '['){
            last = c;
            b++;
        }else if(c == ']'){
            b--;
            if(last == '(' || b < 0){
                cout << "no" << endl;
                return;
            }
            last = c;
        }
    }
    cout << "yes" << endl;
}

int main(int argc, const char * argv[])
{
    while(getline(cin, S), S!="."){
        solve();
    }
    return 0;
}

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

pair<bool, int> square(string s, int i);

pair<bool, int> rounded(string s, int i){
    pair<bool, int> ret;
    for(;i<s.length();++i){
        if(s[i] == '['){
            ret = square(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }else if(s[i] == ']'){
            return (pair<bool, int>){false, i};
        }else if(s[i] == ')'){
            return (pair<bool, int>){true, i};
        }else if(s[i] == '('){
            ret = rounded(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
    }
    return (pair<bool, int>){false, i};
}

pair<bool, int> square(string s, int i){
    pair<bool, int> ret;
    for(;i<s.length();++i){
        if(s[i] == '('){
            ret = rounded(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
        else if(s[i] == ')'){
            return (pair<bool, int>){false, i};
        }else if(s[i] == ']'){
            return (pair<bool, int>){true, i};
        }else if(s[i] == '['){
            ret = square(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
    }
    return (pair<bool, int>){false, i};
}

int main(){
    string s;
    while(getline(cin,s), s[0] != '.'){
        bool flag = false;
        pair<bool, int> ret = pair<bool, int>{true, 0};
        for(int i=0;i<s.length();++i){
            if(s[i] == '('){
                ret = rounded(s, i+1);
                if(ret.first == false){
                    flag = true;
                    printf("no\n");
                    break;
                }
                i = ret.second;
            }else if(s[i] == '['){
                ret = square(s, i+1);
                if(ret.first == false){
                    flag = true;
                    printf("no\n");
                    break;
                }
                i = ret.second;
            }else if(s[i] == ')' || s[i] == ']'){
                printf("no\n");
                flag = true;
                break;
            }
        }
        if(flag == false && ret.first == true)printf("yes\n");
        else if(flag == false)printf("no\n");
    }
    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 f1=0;
  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;i++)
	  if(ch[i]=='[')count2++;
	  else if(ch[i]==']')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;i++)
	  if(ch[i]=='(')count2++;
	  else if(ch[i]==')')count2--;
	break;
      }
  }

  if(count2>=1)f=1;
}

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;
		}

		if (str[strlen(str) - 1] == '\n'){
			str[strlen(str) - 1] = '\0';
		}

		sp = 0;
		for (i = 0; str[i] != '\0' && sp >= 0; 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] == '\0' && str[i - 1] == '.'){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}