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++: //8:26
#include<iostream>
#include<stack>
#include<string>

using namespace std;

int main(){
  for(string s;getline(cin,s),s!=".";){
    int i;
    stack<char> stk;
    for(i=0;i<s.size();i++){
      switch(s[i]){
      case')':
	if(stk.empty()||stk.top()!='('){
	  goto fail;
	}
	stk.pop();
	break;
      case']':
	if(stk.empty()||stk.top()!='['){
	  goto fail;
	}
	stk.pop();
	break;
      case '(':
      case'[':
	stk.push(s[i]);
      }
    }
    if(!(i<s.size())&&stk.empty()){
      cout<<"yes"<<endl;
    }else{
    fail:
      cout<<"no"<<endl;
    }
  }
  return 0;
}

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

int main(){
    while (1){
        string s;
        getline(cin, s);
        if (s.size() == 1 && s[0] == '.') break;
        vector<char> tmp;
        int left_round = 0;
        int left_angle = 0;

        int k = s.size();
        for (int i = 0; i < k; i++){
            if (s[i] == '('){
                tmp.push_back('(');
                left_round++;
            }
            else if (s[i] == ')'){
                if (left_round < 1 || tmp.size() < 1 || tmp.back() != '('){
                    left_round = 1;
                    break;
                }
                else {
                    left_round--;
                    tmp.pop_back();
                }
            }
            else if (s[i] == '['){
                left_angle++;
                tmp.push_back('[');
            }
            else if (s[i] == ']'){
                if (left_angle < 1 || tmp.size() < 1 || tmp.back() != '['){
                    left_angle = 1;
                    break;
                }
                else {
                    left_angle--;
                    tmp.pop_back();
                }
            }
        }
        if (left_round == 0 && left_angle == 0) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

const char a[] = {'(', '['};
const char b[] = {')', ']'};

int main () {
    string str;
    while (getline(cin, str), str.size() > 1) {
        stack<char> s;
        bool ans = true;
        for (int i = 0; i < str.size(); i++) {
            if ('a' > str[i] || str[i] > 'z') {
                if (str[i] == a[0] || str[i] == a[1]) {
                    s.push(str[i]);
                } else if (str[i] == b[0] || str[i] == b[1]) {
                    if (s.empty()) {
                        ans = false; break;
                    } else if (str[i] == b[0] && s.top() == a[0]) {
                        s.pop();
                    } else if (str[i] == b[1] && s.top() == a[1]) {
                        s.pop();
                    } else {
                        ans = false; break;
                    }
                }
            }
        }
        if (s.size() != 0) ans = false;

        cout << (ans ? "yes" : "no") << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

typedef pair<int, int> Pi;
#define fi first
#define se second

signed main()
{
  string S;
  bool izryt = false, flag = true;
  stack < char > st;
  
  cin.ignore();
  while(getline(cin, S), izryt || S != ".") {
    izryt = true;
    Rep(i, S.size()) {
      if(S[i] == '.' && i == (int)S.size() - 1) {
	izryt = false;
      } else if(S[i] == '(' || S[i] == '[') {
	st.push(S[i]);
      } else if(S[i] == ')' || S[i] == ']') {
	if(!st.empty() && (S[i] == ')' && st.top() == '(' || S[i] == ']' && st.top() == '[')) {
	  st.pop();
	} else {
	  flag = false;
	}
      }
    }
    if(!izryt) {
      if(flag && st.empty()) cout << "yes" << endl;
      else cout << "no" << endl;

      while(!st.empty()) {
	st.pop();
      }
      flag = true;
    }
  }

  return 0;
}

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

int main(){
  int f=0,f1=0,a;
  string str; 
  int count=0,count1=0;
  while(1){
  cin>>str;
  if(str==".")break;
  }
  a=str.size();
  for(int i=0;i<a-1;i++)
    if(str[i]=='[') count++; 
    else if(str[i]=='{')count1++;
    else if(str[i]=='}')count1--;
    else if(str[i]==']')count--;

    if(count==0 && count1==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  
  return 0;
}

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

stack<char> st;

char str[514];
int slen;

int main() {
	int i;
	while( gets(str) ) {
		if ( str[0] == '.' && str[1] == '\0' )
			break;
		slen = strlen(str);
		for( i = 0; i < slen; i++ ) {
			if ( str[i] == '(' || str[i] == '[' )
				st.push(str[i]);
			if ( str[i] == ')' ) {
				if ( st.empty() || st.top() != '(' )
					break;
				st.pop();
			}
			if ( str[i] == ']' ) {
				if ( st.empty() || st.top() != '[' )
					break;
				st.pop();
			}
		}
		if ( i == slen )
			cout << "yes" << endl;
		else
			cout << "no" << endl;
		while(!st.empty())
			st.pop();
	}
	return 0;
}

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

using namespace std;

int main(void){
	string str;

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

		
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	string s;
	while (getline(cin, s), s != ".") {
		stack<char>st;
		bool flag = true;
		for (char c : s) {
			if (c == '[' || c == '(')
				st.push(c);
			if (c == ']') {
				if (st.size() && st.top() == '[')
					st.pop();
				else {
					puts("no");
					flag = false;
					break;
				}
			}
			if (c == ')') {
				if (st.size() && st.top() == '(')
					st.pop();
				else {
					puts("no");
					flag = false;
					break;
				}
			}
		}
		if (flag) {
			if (st.size())puts("no");
			else puts("yes");
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

int main(){
	while(1){
		string str; getline(cin,str);
		stack<char> st ;
		if (str == ".") break;
		//cout << str.size() << endl;
		//cout << str << endl;
		for (int i = 0; i < str.size(); i++){
			if (str[i] == '('){
				st.push(str[i]);
			}else if (str[i] == '['){
				st.push(str[i]);
			}else if (str[i] == ')'){
				if (st.empty()){
					st.push(str[i]);
				}else if (st.top() == '('){
					st.pop();
				}else{
					st.push(str[i]);
				}
			}else if (str[i] == ']'){
				if (st.empty()){
					st.push(str[i]);
				}else if (st.top() == '['){
					st.pop();
				}else{
					st.push(str[i]);
				}
			}
		}
		if (st.empty()){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	
	}
return 0;
}