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 <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;
}