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;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	while(1){
		bool ok=true;
		string s;
		while(1){
			char c;
			cin.get(c);
			s+=c;
			if(c=='\n')break;
		}
		if(s==".\n")break;
		int a=0,b=0;
		vector<char> v;
		rep(i,s.size()){
			if(s[i]=='(')a++,v.push_back('(');
			else if(s[i]==')'){
				a--;
				if(a<0||b<0){
					ok=false;
					break;
				}
				if(v[v.size()-1]=='(')v.pop_back();
				else ok=false;
			}
			else if(s[i]=='[')b++,v.push_back('[');
			else if(s[i]==']'){
				b--;
				if(a<0||b<0){
					ok=false;
					break;
				}
				if(v[v.size()-1]=='[')v.pop_back();
				else ok=false;
			}
		}
		if(a!=0||b!=0)ok=false;
		if(ok?print("yes"):print("no"));
	}



}

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



int main(){


  while(1){

    string s;
    int i;
    stack <char> stack;
    bool ans = 1;
   //cin テ」ツ?ッテァツゥツコテァツ卍ステ」ツ?ァテァツオツづ」ツつ湘」ツつ?

    getline(cin, s);
    if(s == ".") break;
    
    stack.push('a');

    for(i = 0 ; i < s.size(); i++){
      if(s[i] == '(' || s[i] == '['){
	stack.push(s[i]);
      }
      if(s[i] == ')'){
	//	cout << "IN ";
	if(stack.top() == '('){
	  //	  cout << "IN "<< stack.top();
	  stack.pop();
	}else{
	  ans = 0;
	  break;
	}
      }
      if(s[i] == ']'){ 
      	if(stack.top() == '['){
	  stack.pop();
	}else{
	  ans = 0;
	  break;
	}
      }      
    }
    
    if(stack.top() != 'a') ans = 0;

    if(ans == 1 ) cout << "yes" << endl;
    else cout << "no" << endl;  
    
  }
  return 0;
}

C++: #include <stdio.h>
int main(){
  int i,ib;
  char a,s[100];
  while(1){
    i=0;
    scanf("%c",&a);
    if(a=='.')break;
    else if(a=='('){
      s[i]='(';
      i++;
    }else if(a==')'){
      s[i]=')';
      i++;
    }else if(a=='['){
      s[i]='[';
      i++;
    }else if(a==']'){
      s[i]=']';
      i++;
    }
    while(1){
      scanf("%c",&a);
      if(a=='.'){
	if(i==0){
	  printf("Yes\n");
	  break;
	}else {
	  printf("No\n");
	  break;
	}
      }else if(a=='('){
	s[i]='(';
	i++;
      }else if(a==')'){
	if(s[i-1]=='(')i--;
	else {
	  s[i]=')';
	  i++;
	}
      }else if(a=='['){
	s[i]='[';
	i++;
      }else if(a==']'){
	if(s[i-1]=='[')i--;
	else {
	  s[i]=']';
	  i++;
	}
      }
    }
    scanf("%c",&a);
  }
  return 0;
}

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

int main(void){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool f=true;
    for(int i=0;i<c.length();i++){
      if(s.empty() || c[i]=='(' || c[i]=='[')s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']')){
	s.pop();
      }else{
	f=false;
	break;
      }
      
    }
    cout << (f && s.empty()?"yes":"no") << endl;
  }
  return 0;
}

C++: 
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Stack;


class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	

	void solve(){
		Scanner in = new Scanner(System.in);

		while(in.hasNext()){
			String s = in.nextLine();
			//int n = 0, m = 0;
			boolean flag = true;
			Stack<Integer> st = new Stack<Integer>();

			if(s.equals(".")) break;

			for(int i = 0; i < s.length(); i++){
				if(s.charAt(i) == '(') st.push(1);
				else if(s.charAt(i) == '[') st.push(2);
				else if(s.charAt(i) == ')'){
					if(st.empty() || st.pop() == 2) {
						flag =false;
						break;
					}
				}
				else if(s.charAt(i) == ']'){
					if(st.empty() || st.pop() == 1){
						flag = false;
						break;
					}
				}
			}

			if(flag) System.out.println("yes");
			else System.out.println("no");
		}
		
	}
	

}

C++: #include <iostream>
#include <stack>
using namespace std;
class kakko{
private:
  stack<char> st;
  int flag;//0=input 1=error

  void digest(char a){
    if(a=='('||a=='[')
      st.push(a);
    if(a==')'){
      if(st.top()=='(') st.pop();
	else errork();
    }
    if(a==']'){
      if(st.top()=='[') st.pop();
	else errork();
    }
    if(a=='.'){
      if(st.top()) {st.empty();st.push(0);    cout <<"no\n";}
      else cout <<"yes\n";
    }
  }
  int errork(){
    cout <<"no\n";
    flag=1;
    st.empty();st.push(0);  
  };
public:
  kakko(){
    st.push(0);
    flag=0;
  }
  void eat(char t){

    if(flag){
      if(t=='.') flag=0;
    }
    else digest(t);
  }
};

int main(){
  kakko ka;
  string tmps;
  getline(cin,tmps);
  while(tmps!="."){
    for(int i=0;i<tmps.length();i++)
      ka.eat(tmps[i]);
  getline(cin,tmps);
  }
  return 0;
}

C++: 
#include<iostream>
#include<stack>
using namespace std;
main(){
int i,f;
for(string s;getline(cin,s),s[0]-'.';){
 stack<char> t;
 for(f=i=0;s[i]-'.';i++){
  if(s[i]==40|s[i]==91)t.push(s[i]);
  if(s[i]==41|s[i]==93){
   if(!t.empty()&&s[i]-t.top()<3)t.pop();
   else f=1;
  }
 }
 puts(!f&t.empty()?"yes":"no");
}}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
char str[101];
map<char, char> kako = { {'(',')'},{'[',']'} };
int is_balanced(int s) {
	for (int i = s+1; strlen(str) > i; i++) {
		if (str[i] == '(' || str[i] == '[') {
			i = is_balanced(i)+1;
			if (i == 0) return -1;
		}
		if (str[i] == ')' || str[i] == ']') {
			if(str[i] != kako[str[s]])
				return -1;
			else {
				return i;
			}
		}
	}
	return -1;
}

int main() {
	while (fgets(str,101, stdin)) {
		bool f = true;
		REP(i, strlen(str)) {
			if (str[i] == '(' || str[i] == '[') {
				i = is_balanced(i)+1;
				if (i == 0) {
					printf("no\n");
					f = false;
					break;
				}
			}
		}
		if (f) printf("yes\n");
	}

	return 0;
}