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(){
    char s[101];
    cin.getline(s, 100);
    while(s[0] != '.'){
        int rnd = 0, box = 0, no = 0;
        for(int i = 0; i < sizeof(s); i++){
            if(s[i] == '(') rnd++;
            if(s[i] == '[') box++;
            if(s[i] == ')') rnd--;
            if(s[i] == ']') box--;
            if(s[i] == '\0') break;
            if(rnd < 0 || box < 0){
                no = 1;
                break;
            }
        }
        if(no == 0 && rnd == 0 && box == 0){
            printf("yes\n");
        } else {
            printf("no\n");
        }
        cin.getline(s, 100);
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	for(;;){
		string word;
		int log[2] = {0};
		getline(cin,word);
		if(word == "."){break;}
		for(int i=0; i<word.size(); i++){
			if(word[i] == '('){log[0]++;}
			if(word[i] == ')'){log[0]--;}
			if(word[i] == '['){log[1]++;}
			if(word[i] == ']'){log[1]--;}
		}
		if(!log[0] && !log[1]){cout <<"yes"<<endl;}
		else{cout <<"no"<<endl;}
	}
}

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

using namespace std;

int main(void)
{
	char c;

	while(1){
		cin.get(c);
		if(c=='.') break;
			
		stack<char> s;
		if(c=='(' || c=='[') s.push(c);
		else if(c==')' || c==']') s.push(c);

		while(1){
			cin.get(c);
			if(c=='.') {
				cin.get(c);
				if(c=='\n') break;
			}

			if(c=='(' || c=='[') s.push(c);
			else if(c==')' && !s.empty() && s.top()=='(') s.pop();
			else if(c==']' && !s.empty() && s.top()=='[') s.pop();
		}

		if(s.empty()) cout << "yes" << endl;
		else cout << "no" << endl;

	}

	return 0;
}

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

using namespace std;

int main(){
  char r[202];
  int count = 101;
  char s;
  char c;
  int maru=0;
  int shikaku=0;
  while(true){
    //はじめの文字の判定
    scanf("%c",&s);
    if(s=='\n')scanf("%c",&s);
    if(s=='.')break;

    if(s=='('){
      r[count++]=')';
      maru++;
    }
    else if(s=='['){
      r[count++]=']';
      shikaku++;
    }
    else if(s==')'){
      if(r[count--]==s){
	maru--;
      }
    }
    else if(s==']'){
      if(r[count--]==s){
	shikaku--;
      }
    }
    //終了条件ではないとき
  while(true){
      cin>>c;
      //    cout<<c;
      if(c=='.'||maru<0||shikaku<0)break;
      else if(c=='('){
	r[count++]=')';
	maru++;
      }
      else if(c=='['){
	r[count++]=']';
	shikaku++;
      }
      else if(c==')'){
	if(r[count-1]==c){
	  count--;
	  maru--;
	}
	else maru=-1111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-1111;
      }
    }
    if(maru==0&&shikaku==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    if(c!='.'){
      while(true){
	cin>>c;
	//    cout<<c;
	if(c=='.')break;
      }
    }
    maru=0;
    shikaku=0;
  }
  return 0;
}

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

bool solve(const string& s) {
    stack<int> stk;
    for(char c : s) {
        if(c == '(') stk.push(1);
        if(c == ')') {
            if(stk.empty() || stk.top() != 1) return false;
            stk.pop();
        }
        if(c == '[') stk.push(2);
        if(c == ']') {
            if(stk.empty() || stk.top() != 2) return false;
            stk.pop();
        }
    }
    return stk.empty();
}

int main() {
    while(true) {
        string s;
        getline(cin, s);
        if (s == ".") break;
        cout << (solve(s) ? "yes" : "no") << endl;
    }
}

C++: //package aoj;

import java.util.Scanner;
import java.util.Stack;

class Main {
    public static boolean solve(String sentence) {
        Stack<Character> stk = new Stack<>();
        for (int i = 0; i < sentence.length(); i++) {
            if(sentence.charAt(i) == '[' || sentence.charAt(i) == '(') stk.push(sentence.charAt(i));
            else if(sentence.charAt(i) == ']') {
                if(stk.empty()) return false;
                if(stk.peek() != '[') return false;
                stk.pop();
            }
            else if(sentence.charAt(i) == ')') {
                if(stk.empty()) return false;
                if(stk.peek() != '(') return false;
                stk.pop();
            }
        }
        return stk.empty();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            String sentence = sc.nextLine();
            System.out.println(solve(sentence) ? "yes" : "no");
        }
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

bool doesBalance(std::string s){
    std::stack<char> stack;
    REP(i, s.size()){
        if(s[i] == '(' || s[i] == '['){
            stack.push(s[i]);
        }else if(s[i] == ')'){
            if(stack.empty() || stack.top() != '('){return false;}
            stack.pop();
        }else if(s[i] == ']'){
            if(stack.empty() || stack.top() != '['){return false;}
            stack.pop();
        }
    }

    return true;
}

int main(){
    std::string s;
    while(std::getline(std::cin, s), s != "."){
        if(doesBalance(s)){puts("yes");}
        else{puts("no");}
    }
}

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

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

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

using namespace std;

int main(){
	int maru=0,kaku=0;

	string str;
	while(getline(cin,str)){
		if(str.at(0)=='.')break;
		maru=0;
		kaku=0;
		stack<int> s;

		for(int i=0;i<str.size();i++){
			if(str.at(i)=='('){
				maru++;
				s.push(1);
			}
			else if(str.at(i)==')' && maru>0){
				if(s.top()==1){
					maru--;
					s.pop();
				}
			}
			if(str.at(i)=='['){
				kaku++;
				s.push(2);
			}
			else if(str.at(i) ==']' &&kaku>0){
				if(s.top()==2){
					kaku--;
					s.pop();
				}
			}
		}

		if(maru==0&&kaku==0){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}

	return 0;
}