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;

int main(int argc, char const *argv[])
{
	string s;
	while(getline(cin,s),s!=".")
	{
		stack<int> q;
		bool f=1;
		for (int i = 0; i < s.size(); ++i)
		{
			if(s.at(i)=='(') q.push(1);
			else if(s.at(i)=='[') q.push(2);
			else if(s.at(i)==')')
			{
				if(q.size()==0||q.top()!=1) f=0,i=s.size();
				else q.pop();
			}
			else if(s.at(i)==']')
			{
				if(q.size()==0||q.top()!=2) f=0,i=s.size();
				else q.pop();
			}
		}
		if(q.size()==0&&f) cout<<"yes\n";
		else cout<<"no\n";
	}
	return 0;
}

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

using namespace std;

int main(void){

	char inp;
	stack<char> data;
	int flag,flag2;

	while(1){
		flag=0,flag2=0;
		while(!data.empty()) data.pop();
		while(1){
			inp=getchar();
			switch(inp){
				case '(':
					data.push('(');
					break;
				case '[':
					data.push('[');
					break;
				case ')':
					if(data.empty()==1){
						flag=1;
						break;
					}
					if(data.top()=='(') data.pop();
					else flag=1;
					break;
				case ']':
					if(data.empty()==1){
						flag=1;
						break;
					}
					if(data.top()=='[') data.pop();
					else flag=1;
					break;
				default:
					break;
			}
			if(inp=='.') break;
			flag2=1;
		}
		if(flag2==0) break;
		if(flag==0&&data.empty()==1) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		getchar();
	}

	return 0;
}

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||!stk.empty()) cout << "no" << endl;
        else cout <<"yes" << endl;
    }
    return 0;
}

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

int main(){
  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;
  }
  
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	while (1) {
		getline(cin, s);
		if (s.size() == 1 && s[0] == '.') {
			return 0;
		} else {
			bool flag = 0;
			stack<char> v;
			REP(i, s.size())
			{
				if (s[i] == '(') {
					v.push(s[i]);
				}
				if (s[i] == ')') {
					if (v.size() != 0 && v.top() == '(') {
						v.pop();
					} else {
						cout << "no" << endl;
						flag = 1;
					}
				}
				if (s[i] == '[') {
					v.push(s[i]);
				}
				if (s[i] == ']') {
					if (v.size() != 0 && v.top() == '[') {
						v.pop();
					} else {
						cout << "no" << endl;
						flag = 1;
					}
				}
			}
			if (flag == 0) {
				if (v.size() == 0) {
					cout << "yes" << endl;
				} else {
					cout << "no" << endl;
				}
			}
		}
	}
}

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

int main(void) {
    char str[105];
    while(1){
        
        cin.getline(str, sizeof(str));

        if(str[0] == '.') break;
        stack<char> s;
        s.push('0');
        int flag = 1;
        for(int i = 0; str[i] != '\0'; i++){
            if(str[i] == '(') s.push(')');
            if(str[i] == '[') s.push(']');
            if(str[i] == ')'){
                if(s.top() == ')'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
            if(str[i] == ']'){
                if(s.top() == ']'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
        }
        if(flag) cout << "yes" << endl;
    }
    return 0;

}

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

int main(){
  string str;
			
  while(getline(cin, str)){
	if(str == ".") break;
	//cout << str << endl;
	bool flag  = false;
	stack<char> s;
	for(int i = 0; i < str.size(); i++){
	  if(str[i] == '(') s.push(str[i]);
	  else if(str[i] == '[') s.push(str[i]);
	  else if(str[i] == ')'){
		if(s.empty()){
		  flag = true;
		  break;
		}
		
		char tmp = s.top(); s.pop();
		//cout << "if ')' then tmp = " << tmp << endl;
		if(tmp != '('){
		  flag = true;
		  break;
		}
	  }
	  else if(str[i] == ']'){
		if(s.empty()){
		  flag = true;
		  break;

		}
		char tmp = s.top(); s.pop();
		//cout << "if ']' then tmp  = " << tmp << endl;
		if(tmp  != '['){
		  flag = true;
		  break;
		}
	  }
	}
	
	if(flag) cout << "no" << endl;
	else cout << "yes" << endl;
  }
  return 0;
}

C++: #include<stack>
#include<cstdio>
#include<cstring>

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

using namespace std;

int main(){
	for(char s[101];gets(s),strcmp(s,".");){
		bool ok=true;
		stack<char> St;
		rep(i,strlen(s)){
			if(s[i]=='(') St.push(s[i]);
			if(s[i]=='[') St.push(s[i]);
			if(s[i]==')') if(St.empty() || St.top()=='[') { ok=false; break; } else St.pop();
			if(s[i]==']') if(St.empty() || St.top()=='(') { ok=false; break; } else St.pop();
		}
		puts(ok?"yes":"no");
	}

	return 0;
}