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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n, m;

void sitA(string& s) {
  for (int i = 0; i < n; i++) {
    if (s[i] != '#') continue;
    s[i] = 'A';
    return;
  }
}

void sitB(string& s) {
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] != '#') continue;
    if (i - 1 >= 0 && s[i - 1] == 'A') continue;
    if (i + 1 < n && s[i + 1] == 'A') continue;
    s[i] = 'B';
    return;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] != '#') continue;
    s[i] = 'B';
    return;
  }
}

void sitC(string& s) {
  for (int i = 0; i < n; i++) {
    if (s[i] == '#') continue;
    if (i + 1 < n && s[i + 1] == '#') {
      s[i + 1] = 'C';
      return;
    }
    if (i - 1 >= 0 && s[i - 1] == '#') {
      s[i - 1] = 'C';
      return;
    }
  }
  if (n & 1) s[(n + 1) / 2 - 1] = 'C';
  else s[n / 2] = 'C';
}

void sitD(string& s) {
  bool none = true;
  for (int i = 0; i < n; i++) {
    none &= s[i] == '#';
  }
  if (none) {
    s[0] = 'D';
    return;
  }
  vector<int> diff(n, 0);
  int diff_max = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != '#') continue;
    int l = i, r = i;
    while (l >= 0 && s[l] == '#') l--;
    if (l < 0) l = -1000;
    while (r < n && s[r] == '#') r++;
    if (r >= n) r = 1000;
    diff[i] = min(i - l, r - i);
    diff_max = max(diff_max, diff[i]);
  }
  for (int i = 0; i < n; i++) {
    if (diff[i] != diff_max) continue;
    s[i] = 'D';
    return;
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> n >> m, n) {
    string ans = string(n, '#');
    for (int i = 0; i < m; i++) {
      char ch;
      cin >> ch;
      if (ch == 'A') sitA(ans);
      if (ch == 'B') sitB(ans);
      if (ch == 'C') sitC(ans);
      if (ch == 'D') sitD(ans);
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
int m,n,j,k,f,g;
char c[101];
void acta() {
	for (j=0;j<m;j++) if (c[j]=='#') { c[j]='A'; break;}
}

void actb() {
	f=m-1;
	for (j=m-1;j>=0;j--) {
		if (c[j]!='#') continue;
		f=j;
		if (j==m-1) {if (c[m-2]!='A') break; else continue;} 
		if (j==0) {if (c[1]!='A') break; else continue;}
		if (c[j-1]!='A' && c[j+1]!='A') break;
	}
	c[f]='B';
}

void actc() {
	if (g==0) {c[m/2]='C'; return;}
	for (j=0;j<m;j++) {
	 if (c[j]!='#') {
		 if (j<m-1) if (c[j+1]=='#') { c[j+1]='C'; break;}
		 if (j>0) if (c[j-1]=='#') { c[j-1]='C'; break;}
	 }   	
	}
}
void actd() {
	int l=0,sx=0,x=0;
	f=0;
	if (g==0) {c[0]='D';return;}
	for (j=0;j<m;j++) {
		if (c[j]!='#') {
			if (f==0) { x=0; l=j;} else { if ((j-sx)/2>l) { l=(j-sx)/2; x=sx+l;}}
			sx=j; f=1;
		} else if (j==m-1) if (j-sx>l) x=j;
	}
	c[x]='D';
}
int main() {
	int i;
	char a;
	while(cin >> m >> n) {
		if (m+n==0) break;
		for (i=0;i<m;i++) c[i]='#'; c[i]='\0'; g=0;
		for (i=0;i<n;i++) {
			cin >> a;
			switch(a) {
				case 'A': acta(); break;
				case 'B': actb(); break;
				case 'C': actc(); break;
				case 'D': actd(); break;
			}
			g=1;
		}
		cout << c << endl;
	}	 
			  			
	return 0;
}

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

const int N_MAX = 100;

void sitA( char* seat, int n )
{
	int i = 0;
	while( seat[ i ] != '#' ){
		++i;
	}
	seat[ i ] = 'A';
}

void sitB( char* seat, int n )
{
	int i = n - 1;
	while( i > 0 ){
		if( seat[ i ] == '#' ){
			if( seat[ i - 1 ] != 'A' && seat[ i + 1 ] != 'A' ){
				seat[ i ] = 'B';
				return;
			}
		}
		--i;
	}
	while( seat[ i ] != '#' ){
		++i;
	}
	seat[ i ] = 'B';
}

void sitC( char* seat, int n )
{
	int i = 0;
	while( i < n ){
		if( seat[ i ] != '#' ){
			if( seat[ i + 1 ] =='#' ){
				seat[ i + 1 ] = 'C';
				return;
			}
			if( i >= 0 && seat[ i - 1 ] == '#' ){
				seat[ i - 1 ] = 'C';
				return;
			}
		}
		++i;
	}
	seat[ n / 2 ] = 'C';
}

void sitD( char* seat, int n )
{
	int est[ N_MAX ];
	int s, e;
	vector< int > seated;
	for( int i = 0; i < n; ++i ){
		if( seat[ i ] != '#' ){
			seated.push_back( i );
		}
	}
	if( seated.size() == 0 ){
		seat[ 0 ] = 'D';
		return;
	}
	e = seated[ 0 ];
	for( int i = e; i >= 0; --i ){
		est[ i ] = e - i;
	}
	for( int i = 1; i < seated.size(); ++i ){
		s = e;
		e = seated[ i ];
		for( int j = 0; j <= ( e - s - 1 ) / 2; ++j ){
			est[ s + j ] = est[ e - j ] = j;
		}
	}
	for( int i = e; i < n; ++i  ){
		est[ i ] = i - e;
	}
	int estMax = 0, estIdx = 0;
	for( int i = 0; i < n; ++i ){
		if( est[ i ] > estMax ){
			estMax = est[ i ];
			estIdx = i;
		}
	}
	seat[ estIdx ] = 'D'; 
}

void sit( char a, char* seat, int n )
{
	switch( a ){
		case 'A': sitA( seat, n ); break;
		case 'B': sitB( seat, n ); break;
		case 'C': sitC( seat, n ); break;
		case 'D': sitD( seat, n ); break;
	}
}

int main()
{
	int n, m;
	char seat[ N_MAX + 1 ];
	while( cin >> n >> m && ( n || m ) ){
		for( int i = 0; i < n; ++i ){
			seat[ i ] = '#';
		}
		seat[ n ] = '\0';

		for( int i = 0; i < m; ++i ){
			char a;
			cin >> a;
			sit( a, seat, n );
		}
		cout << seat << endl;
	}
	return 0;
}