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>
#include <vector>
using namespace std;

int main(){
  while(true){
    char c;
    vector<char> s;
    cin >> c;
    s.push_back(c);
    if(c == '.')
      break;
    while(c != '.'){
      cin >> c;
      s.push_back(c);
    }
    
    stack<char> st;
    bool flag = false;
    for(int i=0; i<s.size(); i++){
      if(s[i] == '(' || s[i] == '['){
        st.push(s[i]);
        continue;
      }

      if(s[i] == ')'){
        if(st.empty()){
          flag = true;
          break;
        }
        if(st.top() == '('){
          st.pop();
        }else{
          flag = true;
          break;
        }
      }
      if(s[i] == ']'){
        if(st.empty()){
          flag = true;
          break;
        }
        if(st.top() == '['){
          st.pop();
        }else{
          flag = true;
          break;
        }
      }
    }

    if(flag || !st.empty())
      cout << "no" << endl;
    else
      cout << "yes" << endl;
  }
  
  return 0;
}

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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool ok(char c) {
    if (c == '(') return true;
    if (c == ')') return true;
    if (c == '[') return true;
    if (c == ']') return true;
    return false;
}
string s;
void solve() {
    stack<char> st;
    bool ans = true;
    rep(i, s.size()) {
        if (!ok(s[i])) continue;
        if (s[i] == '(' || s[i] == '[') st.push(s[i]);
        if (s[i] == ')') {
            if (st.size() && st.top() == '(')
                st.pop();
            else
                ans = false;
        }
        if (s[i] == ']') {
            if (st.size() && st.top() == '[')
                st.pop();
            else
                ans = false;
        }
    }
    if (ans && st.empty())
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}
int main() {
    while (getline(cin, s)) {
        if (s == ".") break;
        solve();
    }
    return 0;
}

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

stack<bool> s;
char c[128];

int main(){
	char *p;
	bool f;
	while (gets_s(c), c[0] != '.') {
		s = stack<bool>();
		p = &c[0];
		f = false;
		while (*p != '.') {
			switch (*p)
			{
			case'(':
				s.push(true); break;
			case'[':
				s.push(false); break;
			case')':
				if (!s.empty() && s.top()) {
					s.pop();  break;
				}
				f = true;
				break;
			case']':
				if (!s.empty() && !s.top()) {
					s.pop(); break;
				}
				f = true;
				break;
			default:
				break;
			}
			if (f) {
				break;
			}
			p++;
		}
		if (f || !s.empty()) {
			printf_s("no\n");
		}
		else {
			printf_s("yes\n");
		}
	}

	return 0;
}

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

#define loop(lp) for(int i = 0;i < lp;i++)

using namespace std;       
int main(){
  string s;
  stack<int> a;
  int i=0,j=0;
  while(getline(cin,s)){
    while(s[i] != '.'){
      
      if(s[i] == '('){
	a.push('(');  
      }else if(s[i] == ')'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '('){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }else if(s[i] == '[' ){
	a.push('[');  
      }else if(s[i] == ']'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '['){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }
      i++;
    }
    if(i == 0){
      break;
    }
    if(a.size() == 0 && j != 1){
	cout <<"yes"<<endl;
      }else{
	cout<<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
    
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	while (1)
	{
		int id = 0;
		stack<int> stck;
		string str; getline(cin, str);
		if (str[0] == '.') { break; }
		rep(i, (int)str.size())
		{
			switch (str[i])
			{
			case '(':	stck.push(1);	break;
			case '[': stck.push(2); break;
			case ')': 
				if (stck.size() == 0) { id = 1; }
				else if (stck.top() == 1) { stck.pop(); }
				else { id = 1; } break;
			case ']': 
				if (stck.size() == 0) { id = 1; }
				else if (stck.top() == 2) { stck.pop(); }
				else { id = 1; } break;
			}
		}
		if (id == 1) { printf("no\n"); }
		else { printf("yes\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; 
    f=0,count=0,count1=0;
    while(1){ 
      scanf("%c",&ch[j]); 
      if(ch[j]=='.')break; 
      j++; 
    } 
    if(j==0)break; 
    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 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>0)f=1; 
}

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;
		cout << str << endl;
		l = strlen(str);
		for(int i = 0; i < l; i++){
			if(str[i] == '(' || str[i] == '['){
				ans = search(i, str[i]);
				if(ans == 0) 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;
	if(c == '('){
		for(int j = i+1; j<l; j++){
			if(str[j] == ')'){
				str[j] = '0';
				return 1;
			}
		}
	} else if(c == '['){
		for(int j = i+1; j<l; j++){
			if(str[j] == ']'){
				str[j] = '0';
				return 1;
			}
		}
	}
	return 0;
}