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 <cstdio>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;

int main()
{
	stack<char> s;

	while (true){
		char str[128];
		fgets(str, sizeof(str), stdin);

		if (str[0] == '.'){
			break;
		}

		bool flag = 1;
		for (int i = 0; str[i] != '.'; i++){
			if (str[i] == '('){
				s.push('(');
			}
			if (str[i] == '{'){
				s.push('{');
			}
			if (str[i] == ')'){
				if (s.top() == '('){
					s.pop();
				}
				else {
					flag = false;
				}
			}
			if (str[i] == '}'){
				if (s.top() == '}'){
					s.pop();
				}
				else {
					flag = false;
				}
			}
		}

		if (flag){
			puts("Yes");
		}
		else {
			puts("No");
		}
	}

	return (0);
}

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

int main(){
  char ch;
  while(1){
    stack<char> S;
    scanf("%c",&ch);
    if(ch=='.')break;
    int i=0;
    bool flag=0;

    while(1){
      if(i!=0)scanf("%c",&ch);
      if(ch=='.')break;
      
      if(ch=='[') S.push('[');
      else if(ch==']'&&S.size()==0)flag=1;
      else if(ch==']'&&S.top()=='[') S.pop();
      
      if(ch=='(')S.push('(');
      else if(ch==')'&&S.size()==0)flag=1;
      else if(ch==')'&&S.top()=='(') S.pop();

      i++;
    }

    if(S.size()==0&&flag!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;

    scanf("%c",&ch);
  }
  return 0;
}

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

int main(){
  char ch;
  int f1=0,f2=0;

  while(1){
    stack<int> S1,S2;
    f1=f2=0;
    scanf("%c",&ch);
    int i=0;
    bool flag1=0,flag2=0;
    if(ch=='.')break;
    while(1){
      if(i!=0) cin>>ch;

      if(ch=='.') break;
      if(ch=='('){
	S1.push(i);
	if(f2==1) f1=2;
	else f1=1;
      }else if(ch==')'&S1.empty()) flag1==1;
      else if(ch==']'&&S2.empty())flag2==1;    
      else if(ch==')'&&S1.size()>0&&f2!=2){
	S1.pop();
	f1=0;
      }else if(ch=='['){
	S2.push(i);
	if(f1==1)f2=2;
	else f2=1;
      }else if(ch==']'&&S2.size()>0&&f1!=2){
	S2.pop();
	f2=0;
      }
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag1!=1&&flag2!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
  
  return 0;
}

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

int main(){
	string str;
	while(getline(cin,str)){
		stack<int> st;
		bool ok = true;
		if(str.size() == 1 && str[0] == '.') break;
		for(int i = 0; i < str.size(); i++){
			if(str[i] == '(') st.push(1);
			else if(str[i] == '[') st.push(2);
			else if(str[i] == ')'){
				if(st.size()==0||st.top() != 1){
					ok = false;
					break;
				} else{
					st.pop();
				}
			}
			else if(str[i] == ']'){
				if(st.size()==0||st.top() != 2){
					ok = false;
					break;
				} else{
					st.pop();
				}
			}
		}
		if(st.size() != 0) ok = false;
		if(ok) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

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

bool solve(string S) {
    stack<char> stk;
    stk.push('#');
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '(')
            stk.push('(');
        else if (S[i] == '[')
            stk.push('[');
        else if (S[i] == ')') {
            if (stk.top() != '(') return false;
            stk.pop();
        } else if (S[i] == ']') {
            if (stk.top() != '[') return false;
            stk.pop();
        }
    }
    return (stk.top() == '#');
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    while (1) {
        getline(cin, S);
        if (S[0] == '.') break;
        cout << (solve(S) ? "yes" : "no") << endl;
    }
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	string str;
	stack<int> st;
	char c;

	while(cin >> c, str += c, c!='.');

	st.push(2);

	FOR(i, 0, str.size()) {
		char c = str[i];

		if(c == '(') {
			st.push(0);
		} else if(c == '[') {
			st.push(1);
		} else if(c == ')') {
			if(st.top() != 0) {
				cout << "no" << endl;
				return 0;
			}
			st.pop();
		} else if(c == ']') {
			if(st.top() != 1) {
				cout << "no" << endl;
				return 0;
			}
			st.pop();
		}
	}

	if(st.top() == 2) {
		cout << "yes" << endl;
		return 0;
	} else {
		cout << "no" << endl;
		return 0;
	}
}

C++: #include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

int main(void)
{
	string str;
	while(getline(cin, str) && str != "."){
		bool flag = true;
		stack<char> st;
		for(int i = 0; i < str.size(); i++){
			if(str[i] == '(' || str[i] == '[') st.push(str[i]);
		
			if(str[i] == ']'){
				if(st.size() != 0 && st.top() == '[') st.pop();
				else { flag = false; break; }
			}
			if(str[i] == ')'){
				if(st.size() != 0 && st.top() == '(') st.pop();
				else { flag = false; break; }
			}
		}
		if(flag && st.size() == 0) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

char line[100];
char str[] = ".";
stack<char> maru, kaku;

int main(){
	while(1){
		fgets(line, 100, stdin);
		if(strcmp(line, str) == 0) break;
		bool def = true;
		for(int i = 0; i < strlen(line); i++){
			if(line[i] == '(') maru.push(line[i]);
			if(line[i] == ')'){
				if(maru.empty()){
					def = false;
					break;
				}else maru.pop();
			}
			if(line[i] == '[') kaku.push(line[i]);
			if(line[i] == ']'){
				if(kaku.empty()){
					def = false;
					break;
				}else kaku.pop();
			}
		}
		if(!maru.empty() || !kaku.empty()) def = false;
		if(def == true) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}