Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
		"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		chair := make([]string, n+1)
		for i := range chair {
			chair[i] = "#"
		}
		chair[n] = "Sentinel"
		for i := 0; i < m; i++ {
			scanner.Scan()
			switch who := scanner.Text(); who {
			case "A": // 左から眺めて行って空いている席があったら即座に座る
				for j := 0; j < n; j++ {
					if chair[j] == "#" {
						chair[j] = "A"
						break
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "B":
				flag := true
				// 右端からAの隣でない席を探していく
				for j := n-1; j > -1; j-- {
					if chair[j] == "#" && (j == 0 || chair[j-1] != "A") && chair[j+1] != "A" {
						flag = false
						chair[j] = "B"
						break
					}
				}
				// Aの隣しか空いていないので一番左端の空いている席に座る
				if flag {
					for j := 0; j < n; j++ {
						if chair[j] == "#" {
							chair[j] = "B"
							break
						}
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "C":
				if i == 0 {
					chair[n/2] = "C" // 先客が誰もいないときは真ん中の椅子に座る
				} else {
					for j := 0; j < n; j++ { // 左から舐めて
						if chair[j] != "#" { // その席が空いていなくて
							if chair[j+1] == "#" { // 右隣が空いているなら座る
								chair[j+1] = "C"
								break
							} else if j != 0 && chair[j-1] == "#" { // 右隣が空いていないので左隣に座る
								chair[j-1] = "C"
								break
							}
						}
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "D":
				distanceTable := make([]int ,n)
				for j := range distanceTable {
					distanceTable[j] = INF
				}
				for j:= 0; j < n; j++ {
					if chair[j] != "#" {
						for k := 0; k < n; k++ {
							distanceTable[k] = min(distanceTable[k], abs(j-k))
						}
					}
				}
				// log.Println("distanceTAble:", distanceTable)
				at := 0
				distance := 0
				for j := 0; j < n; j++ {
					if distance < distanceTable[j] {
						at = j
						distance = distanceTable[j]
					}
				}
				chair[at] = "D"
				// log.Println(chair)
				break // 次の人を読み込む
			}
		}
		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Println(chair[i])
			} else {
				fmt.Printf("%s ", chair[i])
			}
		}
	}
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
//#include <set>

int n, m; //??????, ???

int main() {
    while(std::cin >> n >> m, n + m) {
        std::string str(n, '#');

        char q;
        for(int a = 0; a < m; ++a) {
            std::cin >> q;

            bool ok;
            switch(q) {
            case 'A':
                str[str.find("#")] = 'A';
                break;
            case 'B':
                ok = false;
                for(int i = n - 1; i >= 0; --i) {
                    if((i == 0 || str[i - 1] != 'A') && (i == n - 1 || str[i + 1] != 'A')) {
                        ok = true;
                        str[i] = 'B';
                        break;
                    }
                }
                if(!ok) {
                    str[str.find("#")] = 'B';
                }
                break;
            case 'C':
                ok = false;
                for(int i = 0; i < n; ++i) {
                    if(str[i] != '#') {
                        if(str[i + 1] == '#') {
                            str[i + 1] = 'C';
                            ok = true; break;
                        }
                        if(i != 0) {
                            str[i + 1] = 'C';
                            ok = true; break;
                        }
                    }
                }

                if(!ok) {
                    str[n / 2] = 'C';
                }
                break;
            case 'D':
                int dist[101];
                for(int i = 0; i < n; ++i) {
                    int d = 1e+9;
                    if(str[i] == '#') {
                        for(int j = 0; j < n; ++j) {
                            if(str[j] != '#') {
                                d = std::min(d, std::abs(i - j));
                            }
                        }
                    }
                    
                    dist[i] = d;
                }

                int minIdx = 0;
                for(int i = 0; i < n; ++i) {
                    if(dist[i] < dist[minIdx]) {
                        minIdx = i;
                    }
                }

                str[minIdx] = 'D';

                break;
            }
        }

        std::cout << str << std::endl;
    }
}

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

using namespace std;

void PersonA(string&);
void PersonB(string&);
void PersonC(string&);
void PersonD(string&);
int SeatCheck(int, string);
bool NotEmptySeat(const char&);

int main(){
  int i, n, m;
  string c;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    string chair(n, '#');

    for(i=0; i<m; ++i){
      cin >> c;

      if(c == "A") PersonA(chair);
      else if(c == "B") PersonB(chair);
      else if(c == "C") PersonC(chair);
      else if(c == "D") PersonD(chair);
    }

    cout << chair << endl;
  }

  return 0;
}

void PersonA(string& s){
  string::iterator iter;

  iter = find(s.begin(), s.end(), '#');
  *iter = 'A';
}

void PersonB(string& s){
  int i, isFound = 0;
  string::iterator iter;

  if(s[s.size()-1] == '#' && s[s.size()-1] != 'A'){
    s[s.size()-1] = 'B';
    isFound = 1;
  }else{
    for(i=s.size()-2; i>0; --i){
      if(s[i] == '#' && s[i-1] != 'A' && s[i+1] != 'A'){
	s[i] = 'B';
	isFound = 1;
	break;
      }
    }
    if(isFound == 0){
      if(s[0] == '#' && s[1] != 'A'){
	s[0] = 'B';
	isFound = 1;
      }
    }
  }

  if(isFound == 0){
    iter = find(s.begin(), s.end(), '#');
    *iter = 'B';
  }
}

void PersonC(string& s){
  string::iterator iter1, iter2;

  iter1 = find_if(s.begin(), s.end(), NotEmptySeat);
  if(iter1 == s.end()){
    if(s.size()%2 == 1) s[(s.size()-1)/2] = 'C';
    else s[s.size()/2] = 'C';
  }else{
    iter2 = find(iter1 +1, s.end(), '#');
    if(iter2 == s.end()) *(iter1 -1) = 'C';
    else *iter2 = 'C';
  }
}

void PersonD(string& s){
  int i, n, count=0, _count, countleft, countright;
  string::iterator iter;

  iter = find_if(s.begin(), s.end(), NotEmptySeat);
  if(iter == s.end()){
    s[0] = 'D';
  }else{
    for(i=0; i<s.size(); ++i){
      if(s[i] == '#'){
	_count = SeatCheck(i, s);
	if(_count > count){
	  n = i;
	  count = _count;
	}
      }
    }

    if(count == 0){
      iter = find(s.begin(), s.end(), '#');
      *iter = 'D';
    }else{
      s[n] = 'D';
    }
  }
}

int SeatCheck(int n, string s){
  int i, count1, count2, isFound1=0, isFound2=0;

  for(i=n-1, count1=0; i>=0; --i, ++count1){
    if(s[i] != '#'){
      isFound1 = 1;
      break;
    }
  }
  for(i=n+1, count2=0; i<s.size(); ++i, ++count2){
    if(s[i] != '#'){
      isFound2 = 1;
      break;
    }
  }

  if(isFound1 == 0){
    return count2;
  }else if(isFound2 == 0){
    return count1;
  }else{
    if(count1 < count2) return count1;
    else return count2;
  }
}

bool NotEmptySeat(const char& c){
  if(c == '#') return false;
  else return true;
}