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 // 次の人を読み込む
			}
		}
		fmt.Println(strings.Join(chair[:len(chair)-1], ""))
	}
}

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 <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector<char> v(n+2);
        for (int _ = 0; _ < m; ++_) {
            char c;
            cin >> c;
            if(c == 'A'){
                for (int j = 1; j <= n; ++j) {
                    if(!v[j]){
                        v[j] = c;
                        break;
                    }
                }
            }else if(c == 'B'){
                int ok = 0;
                for (int j = n; j >= 1; --j) {
                    if(!v[j] && v[j-1] != 'A' && v[j+1] != 'A'){
                        v[j] = c;
                        ok = 1;
                        break;
                    }
                }
                if(!ok){
                    for (int j = 1; j <= n; ++j) {
                        if(!v[j]){
                            v[j] = c;
                            break;
                        }
                    }
                }
            }else if(c == 'C'){
                int ok = 0;
                for (int j = 1; j <= n; ++j) {
                    if(!v[j]) continue;;
                    if(j != n && !v[j+1]){
                        v[j+1] = c;
                        ok = 1;
                        break;
                    }
                    if(j != 1 && !v[j-1]){
                        v[j-1] = c;
                        ok = 1;
                        break;
                    }
                }
                if(!ok){
                    v[(n+2)/2] = c;
                }
            }else if(c == 'D'){
                int cur = 1, dist = 0;
                for (int j = 1; j <= n; ++j) {
                    if(v[j]) continue;
                    int d = INF<int>;
                    for (int k = 1; k <= n; ++k) {
                        if(v[k]){
                            d = min(d, abs(j-k));
                        }
                    }
                    if(d > dist){
                        dist = d;
                        cur = j;
                    }
                }
                v[cur] = c;
            }
        }
        for (int i = 1; i <= n; ++i) {
            if(v[i]) cout << v[i];
            else cout << "#";
        }
        puts("");
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int isu[100];
int m;

void A(void){
	for(int i=0;i<m;i++){
		if(isu[i]==0){
			isu[i]=1;
			return;
		}
	}
}
void B(void){
	if(isu[m-1]==0 && isu[m-2]!=1){
		isu[m-1]=2;
		return;
	}
	for(int i=m-2;i>=1;i--){
		if(isu[i]==0 && isu[i+1]!=1 && isu[i-1]!=1){
			isu[i]=2;
			return;
		}
	}
	if(isu[0]==0&&isu[1]!=1){
		isu[0]=2;
		return;
	}
	
	for(int i=0;i<m;i++){
		if(isu[i]==0){
			isu[i]=2;
			return;
		}
	}
}
void C(void){
	int cont=0;
	for(int i=0;i<m;i++){
		cont+=isu[i];
	}
	if(cont==0){
		isu[m/2]=3;
		return;
	}
	
	if(isu[0]==0){
		for(int i=0;i<m;i++){
			if(isu[i]==0&&isu[i+1]!=0){
				isu[i]=3;
				return;
			}
		}
	}else{
		for(int i=0;i<m;i++){
			if(isu[i]==0){
				isu[i]=3;
				return;
			}
		}
	}
}
void D(void){
	int cent=0;
	for(int i=0;i<m;i++){
		cent+=isu[i];
	}
	if(cent==0){
		isu[0]=4;
		return;
	}
	
	int che[100];
	
	int cont=120;
	for(int i=0;i<m;i++){
		cont++;
		if(isu[i]!=0){
			cont=0;
		}
		che[i]=cont;
	}
	cont=120;
	for(int i=m-1;i>=0;i--){
		cont++;
		if(isu[i]!=0){
			cont=0;
		}
		che[i]=min(cont,che[i]);
	}
	int max=-1;
	int ele=0;
	for(int i=0;i<m;i++){
		if(che[i]>max){
			max=che[i];
			ele=i;
		}
	}
	isu[ele]=4;
	return;
}


int main(void){
	
	while(1){
		for(int i=0;i<100;i++){
			isu[i]=0;
		}
		
		int n;
		scanf("%d%d",&m,&n);
		
		if(n==0 && m==0){
			break;
		}
		
		for(int i=0;i<n;i++){
			char ch[10];
			scanf("%s",ch);
			
			switch(ch[0]){
				case 'A':A();break;
				case 'B':B();break;
				case 'C':C();break;
				case 'D':D();break;
			}
		}
		
		for(int i=0;i<m;i++){
			switch(isu[i]){
				case 0:printf("#");break;
				case 1:printf("A");break;
				case 2:printf("B");break;
				case 3:printf("C");break;
				case 4:printf("D");break;
			}
		}
		puts("");
	}
	return 0;
}