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
		}
		chairs := make([]string, n)
		for i := range chairs {
			chairs[i] = "#"
		}
		sit := func(who string) {
			if who == "A" {
				chairs[getStringIndex(chairs, "#")] = "A" // A国の人は左から見て行って空いている席を見つけ次第座る
				// log.Println(chairs)
			} else if who == "B" {
				f := true
				for i := n-1; i > -1; i-- {
					// B国の人はA国人の隣以外で、右端から空いている椅子に座る
					if chairs[i] == "#" && (i == 0 || chairs[i-1] != "A") && (i == n-1 || chairs[i+1] != "A") {
								chairs[i] = "B"
								f = false
								break
					}
				}
				// A国人の隣しか空いていない場合、我慢して左端から空いている椅子に座る
				if f {
					chairs[getStringIndex(chairs, "#")] = "B"
				}
				// log.Println(chairs)
			} else if who == "C" { // C国人は人の隣に座りたい
				for i := 0; i < n; i++ {
					if chairs[i] != "#" {
						if i + 1 <= n-1 && chairs[i+1] == "#" {
							chairs[i+1] = "C"
							break
						} else if i - 1 >= 0 && chairs[i-1] == "#" {
							chairs[i-1] = "C"
							break
						}
					}
				}
				// log.Println(chairs)
			} else { // who == "D"
				// D国の人は人から離れて座りたい
				// どうしても誰かの隣に座らなければならない場合、その中で一番左側にある椅子に座る
				scores := make([]int, n)
				for i := range scores {
					scores[i] = INF
				}
				for i, v := range chairs {
					if v == "#" {
						scores[i]++
					}
				}
				for i := n-1; i > -1; i-- {
					tmp := 0
					if chairs[i] == "#" {
						tmp++
					} else {
						tmp = 0
					}
					scores[i] = min(scores[i], tmp)
				}
				chairs[getIntIndex(scores, getMax(scores))] = "D"
				// log.Println(chairs)
			}
		}
		scanner.Scan()
		if first := scanner.Text(); first == "A" || first == "D" {
			chairs[0] = first
		} else if first == "B" {
			chairs[len(chairs)-1] = "B"
		} else {
			chairs[n/2] = "C"
		}
		// log.Println(chairs)
		for i := 0; i < m-1; i++ {
			scanner.Scan()
			sit(scanner.Text())
		}
		fmt.Println(strings.Join(chairs, ""))
	}
}

func getStringIndex(chairs []string, who string) int {
	for i, v := range chairs {
		if v == who {
			return i
		}
	}
	return -1
}

func getIntIndex(scores []int, target int) int {
	for i, v := range scores {
		if v == target {
			return i
		}
	}
	return -1
}

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

func getMax(scores []int) int {
	tmp := -1
	for _, v := range scores {
		if tmp < v {
			tmp = v
		}
	}
	return tmp
}

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

using namespace std;

void PersonA(string&);
void PersonB(string&);
void PersonC(string&);
void PersonD(string&);
bool UsingSeat(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 i;
  i = find(s.begin(), s.end(), '#');
  *i = 'A';
}

void PersonB(string& s){
  string::reverse_iterator i, j;
  string::iterator k;
  for(j=s.rbegin(); i!=s.rend(); j=i+1){
    i = find(j, s.rend(), '#');
    if((i == s.rbegin() && *(i+1) != 'A') ||
       (i == s.rend()-1 && *(i-1) != 'A') ||
       (*(i-1) != 'A' && *(i+1) != 'A')){
      *i = 'B';
      return;
    }
  }
  k = find(s.begin(), s.end(), '#');
  *k = 'B';
}

void PersonC(string& s){
  string::iterator i, j;
  i = find_if(s.begin(), s.end(), UsingSeat);
  if(i == s.end()){
    s[s.size()/2] = 'C';
    return;
  }
  while(i != s.end()){
    j = find_if(i, s.end(), UsingSeat);
    if(*(j+1) == '#'){
      *(j+1) = 'C';
      return;
    }
    if(*(j-1) == '#'){
      *(j-1) = 'C';
      return;
    }
    ++i;
  }
}

void PersonD(string& s){
  string::iterator i, j, k;
  i = find_if(s.begin(), s.end(), UsingSeat);
  if(i == s.end()){
    s[0] = 'D';
    return;
  }
  int empty, _empty;
  empty = i - s.begin();
  k = s.begin();
  ++i;
  while(1){
    j = find_if(i, s.end(), UsingSeat);
    if(j == s.end()) break;
    _empty = j - i;
    if(_empty%2 == 0 && _empty/2 > empty){
      empty = _empty/2;
      k = i + empty - 1;
    }
    else if(_empty%2 == 1 && _empty/2 + 1 > empty){
      empty = _empty/2 + 1;
      k = i + empty - 1;
    }
    i = j + 1;
  }
  _empty = s.end() - i;
  if(_empty > empty) k = s.end()-1;
  *k = 'D';
}

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

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

int main()
{
  int n, m;
  while (cin >> n >> m) {
    string chair(n, '#');

    while (m--) {
      string a;
      cin >> a;
      if (a == "A") {
	for (int i = 0; i < n; ++i) {
	  if (chair[i] == '#') {
	    chair[i] = 'A';
	    break;
	  }
	}
      } else if (a == "B") {
	bool sit = false;
	for (int i = n-1; i > 0; --i) {
	  if (chair[i] == '#' && chair[i-1] != 'A') {
	    chair[i] = 'B';
	    sit = true;
	    break;
	  }
	}
	if (sit)
	  continue;

	for (int i = 0; i < n; ++i) {
	  if (chair[i] == '#') {
	    chair[i] = 'B';
	    break;
	  }
	}
      } else if (a  == "C") {
	bool sit = false;
	for (int i = 0; i < n-1; ++i) {
	  if (chair[i] != '#' && chair[i+1] == '#') {
	    chair[i+1] = 'C';
	    sit = true;
	    break;
	  }
	}
	if (sit)
	  continue;

	if (n&1)
	  chair[(n+1)/2-1] = 'C';
	else
	  chair[n/2] = 'C';
      } else {
	int maxIndex = -1, dist = -1;
	for (int i = 0; i < n; ++i) {
	  if (chair[i] != '#')
	    continue;

	  int right = 0;
	  if (i == n-1)
	    right = n;
	  for (int j = i+1; j < n; ++j) {
	    if (chair[j] == '#')
	      ++right;
	    else
	      break;
	  }

	  int left = 0;
	  if (i == 0)
	    left = n;
	  for (int j = i-1; j >= 0; --j) {
	    if (chair[j] == '#')
	      ++left;
	    else
	      break;
	  }

	  if (dist < min(right, left)) {
	    maxIndex = i;
	    dist = min(right, left);
	  }
	}
	chair[maxIndex] = 'D';
      }
    }

    cout << chair << endl;
  }
  return 0;
}

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

int main()
{
  int n,m;
  char c,isu[200];
 
  while(1){
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<200;i++)isu[i]='#';

    for(int k=0;k<m;k++){
      cin>>c;
      if(c=='A'){
	for(int i=0;i<n;i++){
	  if(isu[i]=='#'){
	    isu[i]='A';
	    break;
	  }
	}
      }

      if(c=='B'){
	bool flag=false;
	for(int i=n-1;i>=1;i--){
	  if(isu[i-1]!='A' && isu[i]=='#'){
	    isu[i]='B';
	    flag=true;
	    break;
	  }
	}
	if(flag)continue;
	for(int i=0;i<n;i++){
	  if(isu[i]=='#'){
	    isu[i]='B';
	    break;
	  }
	}
      }
      if(c=='C'){
	if(k==0){
	  if(n%2==0){
	    isu[n/2+1-1]='C';
	  }
	  else isu[(n+1)/2-1]='C';
	  continue;
	}
        for(int i = 0;i<n-1;i++){
	  if(isu[i]!='#'){
	    if(isu[i+1]=='#'){
	      isu[i+1]='C';
	      break;
	    }
            if(i!=0 && isu[i-1]=='#'){
	      isu[i-1]='C';
	      break;
	    }
	  }
	}
      }
      if(c=='D') {
	if(k==0){
	  isu[0]='D';
	  continue;
	}
	if(isu[n-1] == '#'){
	  isu[n-1]='D';
	  continue;
	}
	if(isu[0] == '#'){
	  isu[0]='D';
	  continue;
	}

	int ma=0,index;
	for(int i = 0;i < n;i++){
	  if(isu[i] == '#'){
	    for(int j=i+1;j<n;j++){
	      if(isu[j]!='#' ||  j==n-1){
		if(ma<j-i-1){
		  ma=j-i-1;
		  index=i;
		}
		i=j;
		break;
	      }
	    }
	  }
	}
	isu[index+ma/2]='D';
      }
    }
    for(int i=0;i<n;i++)cout<<isu[i];
    cout<<endl;
  }
  return 0;
}