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<stack>
using namespace std;

int main(){

  string str;

  while(getline(cin, str)){
    if(str[0]=='.') break;

    stack<char> s;
    bool f=true;

    for(int i=0;i<str.size();i++){
      if(str[i]=='('||str[i]=='[') s.push(str[i]);
      if(str[i]==')'){
        if(s.empty()){
          f=false;
          break;
        }
        if(s.top()=='(') s.pop();
        else{
          f=false;
          break;
        }
      }else if(str[i]==']'){
        if(s.empty()){
          f=false;
          break;
        }
        if(s.top()=='[') s.pop();
        else{
          f=false;
          break;
        }
      }
    }
    if(f&&s.empty()) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

  return 0;
}

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;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i-1]=='.') break;
        }
        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++: #include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <stack>
using namespace std;
 
int x, y, s;
int main() {
    while(1){
        string str; getline(cin, str);
        
        if(str == ".") break;
        stack<char> stk;
        int n=str.size();
        bool ok = true;
        for(int i=0; i<n; ++i){
            if(str[i]=='('||str[i]=='[') stk.push(str[i]);
            
            if(str[i]==')'){
                if(stk.empty()) ok = false;
                else if(stk.top()=='('){
                    stk.pop();
                }else{
                    ok = false;
                }
            }
            if(str[i]==']'){
                if(stk.empty()) ok = false;
                else if(stk.top()=='['){
                    stk.pop();
                }else{
                    ok = false;
                }
            }
            if(str[i]=='.'||str[i]==' ') continue;
            if(!ok) break;
        }
        if(!ok) cout << "no" << endl;
        else cout <<"yes" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".") { break; }

    bool is_valid = true;

    stack<char> st;

    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '(') { st.push(s[i]); }
      if (s[i] == ')') {
        if ( st.empty() || st.top() != '(') {
          is_valid = false;
          break;
        }
        st.pop();
      }
      if (s[i] == '[') { st.push(s[i]); }
      if (s[i] == ']') {
        if (st.empty() || st.top() != '[') {
          is_valid = false;
          break;
        }
        st.pop();
      }
    }
    if (!st.empty()) { is_valid = false; }
    cout << ( is_valid ? "yes" : "no") << endl;
  }

  return 0;
}

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

      if(ch[i]=='[')count++;
      else if(ch[i]=='(')count1++;
      else if(ch[i]==']'){
	if(count==1&&count1==1)test(i);
	if(f==1)break;
	else  count--;
      }
      else if(ch[i]==')'){
	if(count!=0&&count1!=0)test(i);
	if(f==1)break;
	else  count1--;
      }
    }
    if(count==0 && count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char b;
    scanf("%c",&b);
  }
  return 0;
}
void test(int x){
  f=0;
  int count2;
  if(ch[x]==')')
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='('){
	count2=0;
	for(int j=x-1;j>i;i++)
	  if(ch[i]=='[')count2++;
	  else if(ch[i]==']')count2--;
	if(count2>=1)f=1;
      }
  else
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='['){
	count2=0;
	for(int j=x-1;j>i;i++)
	  if(ch[i]=='(')count2++;
	  else if(ch[i]==')')count2--;
	if(count2>=1)f=1;
      }

}

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

int main() {
	char c;
	int count,flag;
	stack<char> sta;
	while(1){
		count = 0;
		flag = 0;
		while(1){
			scanf("%c",&c);
			if(c == '.')break;
			if(flag == 1)continue;
			if(c == '('){
				sta.push(')');
			}
			else if(c == '['){
				sta.push(']');
			}
			else if(c == ')' || c == ']'){
				if(sta.size() == 0)flag = 1;
				else if(sta.top() != c)flag = 1;
				if(sta.size() > 0)sta.pop();
			}
			count++;
		}
	if(count == 1)break;
	if(flag == 0 && sta.size() == 0)cout << "yes" <<endl;
	else if(flag == 1 || sta.size() > 0)cout << "no" <<endl;
	while(sta.size() != 0){
		sta.pop();
	}
	}
	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    string s;
    while(true)
    {
        getline(cin,s);
        if(s == ".") break;
        
        stack<char> st;
        bool flag = true;
        rep(i,s.size()) {
            if(!flag) break;

            if(s[i] == '(') {
                st.push(s[i]);
            }
            if(s[i] == ')') {
                if(st.size() == 0) flag = false;
                else {
                    if(st.top() == '(') st.pop();
                    else flag = false;
                }
            }
            if(s[i] == '[') {
                st.push(s[i]);
            }
            if(s[i] == ']') {
                if(st.size() == 0) flag = false;
                else {
                    if(st.top() == '[') st.pop();
                    else flag = false;
                }
            }
        }

        if(flag && st.size() == 0) cout << "yes" << endl;
        else cout << "no" << endl;
        
    }

    return 0;
}