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<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int ans[111];

int calc(int x, int n) {
	int l = 0;
	for (; l <= x; l++) {
		if (ans[x-l] != -1) break;
	}
	if (l == x+1) l = n;
	int r = 0;
	for (; r+x < n; r++) {
		if (ans[r+x] != -1) break;
	}
	if (r+x == n) r = n;
	return min(l, r);
}

int main() {
	int N, M;
	while (cin >> N >> M) {
		if (N == 0 && M == 0) break;
		memset(ans, -1, sizeof(ans));
		for (int t = 0; t < M; t++) {
			char c;
			cin >> c;
			if (c == 'A') {
				for (int i = 0; i < N; i++) {
					if (ans[i] == -1) {
						ans[i] = 0;
						break;
					}
				}
			}
			if (c == 'B') {
				bool done = false;
				for (int i = N-1; i >= 0; i--) if (ans[i] == -1) {
					if (ans[i+1] != 0) {
						if (i == 0 || ans[i-1] != 0) {
							done = true;
							ans[i] = 1;
							break;
						}
					}
				}
				if (!done) {
					for (int i = 0; i < N; i++) {
						if (ans[i] == -1) {
							ans[i] = 1;
							break;
						}
					}
				}
			}
			if (c == 'C') {
				if (t == 0) {
					ans[(N+1)/2] = 2;
				} else {
					for (int i = 0; i < N; i++) {
						if (ans[i] != -1) {
							if (i+1 < N && ans[i+1] == -1) {
								ans[i+1] = 2;
								break;
							} else if (i > 0 && ans[i-1] == -1) {
								ans[i-1] = 2;
								break;
							}
						}
					}
				}
			}
			if (c == 'D') {
				if (t == 0) {
					ans[0] = 3;
				} else {
					int index = 0, maxi = 0;
					for (int i = 0; i < N; i++) if (ans[i] == -1) {
						int tmp = calc(i, N);
						if (tmp > maxi) {
							maxi = tmp;
							index = i;
						}
					}
					ans[index] = 3;
				}
			}
		}
		for (int i = 0; i < N; i++) {
			if (ans[i] == 0) cout << 'A';
			else if (ans[i] == 1) cout << 'B';
			else if (ans[i] == 2) cout << 'C';
			else if (ans[i] == 3) cout << 'D';
			else cout << '#';
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long n,m,i,j,d[101],e[101],k,dd;
char c,a[101];
while(cin>>n){
cin>>m;
if(n==0)break;
for(i=0;i<n;i++)a[i]='#';
for(j=0;j<m;j++){
cin>>c;
if(c=='A'){
for(i=0;i<n;i++)if(a[i]=='#'){a[i]='A';break;}
}else if(c=='B'){
for(i=n-1;i>=0;i--){
if(a[i]!='#')continue;
if(0<i&&i<n-1&&a[i-1]!='A'&&a[i+1]!='A'){a[i]='B';break;}
else if(0<i&&a[i-1]!='A'){a[i]='B';break;}
else if(i<n-1&&a[i+1]!='A'){a[i]='B';break;}
}
if(i<0){for(i=0;i<n;i++)if(a[i]=='#'){a[i]='B';break;}}
}else if(c=='C'){
for(i=0;i<n;i++){
if(a[i]!='#'){
if(i<n-1&&a[i+1]=='#'){a[i+1]='C';break;}
else if(i>0&&a[i-1]=='#'){a[i-1]='C';break;}
}
}
if(i==n)a[n/2]='C';
}else if(c=='D'){
for(i=0;i<n;i++)d[i]=-1;
for(i=0;i<n;i++)if(a[i]!='#')break;
if(i==n){a[0]='D';continue;}
for(;i<n;i++)if(a[i]=='#')d[i]=d[i-1]+1;else d[i]=0;
for(i=0;i<n;i++)e[i]=-1;
for(i=n-1;i>=0;i--)if(a[i]!='#')break;
for(;i>=0;i--)if(a[i]=='#')e[i]=e[i+1]+1;else e[i]=0;
for(i=0;i<n;i++)if(d[i]<e[i])d[i]=e[i];
dd=d[n-1];
for(i=n-1;i>=0;i--)if(dd<=d[i]){dd=d[i];k=i;}
a[k]='D';
}
}
a[n]=0;cout<<a<<endl;
}
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n,m;
char chair[200]={};

void A(char ch){
  int i=1;
  while(chair[i]!='#') i++;
  chair[i]=ch;
}

void B(){
  int i=n;
  while(chair[i]!='#')i--;
  chair[i]='B';
}

void C(int kai){
  if(kai==0){
    if(n%2)chair[(n+1)/2]='C';
    else chair[n/2+1]='C';
    return;
  }
  for(int i=1;i<=n;i++){
    if(chair[i]=='#')continue;
    if(chair[i+1]=='#') chair[i+1]='C',i=n;
    if(chair[i-1]=='#') chair[i-1]='C',i=n;

  }
}

void D(){
  int R=0,L=0;
  while(chair[n-R]=='#')R++;
  while(chair[L+1]=='#')L++;
  
  int M=0,idx=0,cnt=0;
  for(int i=1;i<=n;i++){
    if(chair[i]=='#')cnt++;
    else cnt=0;
    if(M+M%2<cnt) M=cnt,idx=i;
  }
  if(M<=2&&L<=1&&R<=1) A('D');
  else if(L-1>=(M-1)/2&&L-1>=R-1)chair[1]='D';
  else if(R-1>(M-1)/2)chair[n]='D';
  else chair[(idx-M+1)+(M-1)/2]='D';

}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    memset(chair,'#',sizeof(chair));
    chair[0]=chair[n+1]=0;
    for(int i=0;i<m;i++){
      char a;
      cin>>a;
      if(a=='A') A(a);
      if(a=='B') B();
      if(a=='C') C(i);
      if(a=='D') D();
    }
    assert(strlen(chair+1)==n);
    printf("%s\n",chair+1);
  }
  return 0;
}