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, ""))
	}
}

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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};


void f(string &s, char op){
    
    int n = s.size();
    if(op == 'A'){
        for(int i = 0; i < n; i++){
            if(s[i] == '#'){
                s[i] = 'A';
                return;
            }
        }
        
    }

    if(op == 'B'){
        for(int i = n - 1; i >= 0; i--){
            if(s[i] != '#') continue;

            if(i == n - 1){
                if(s[i - 1] != 'A'){
                    s[i] = 'B';
                    return;
                }
            }else if(i == 0){
                if(s[i + 1] != 'A'){
                    s[i] = 'B';
                    return;
                }
            }else{
                if(s[i - 1] != 'A' && s[i + 1] != 'A'){
                    s[i] = 'B';
                    return;
                }
            }
        }

        for(int i = 0; i < n; i++){
            if(s[i] == '#'){
                s[i] = 'B';
                return;
            }
        }
    }

    if(op == 'C'){
        
        bool check = false;
        for(int i = 0; i < n; i++){
            if(s[i] != '#') check = true;
        }

        if(check){
            for(int i = 0; i < n; i++){
                if(s[i] != '#'){
                    if(i != n - 1 && s[i + 1] == '#'){
                        s[i + 1] = 'C';
                        return;
                    }else if(i != 0 && s[i - 1] == '#'){
                        s[i - 1] = 'C';
                        return;
                    }
                }
            }
        }else{
            int idx = n / 2;
            s[idx] = 'C';
            return;
        }
    }

    if(op == 'D'){
        vector<int> v(n, INF);
        for(int i = 0; i < n; i++) if(s[i] != '#') v[i] = 0;
        for(int i = 0; i < n; i++){
            if(s[i] != '#'){
                int dis = 0;
                for(int j = i + 1; j < n; j++){
                    dis++;
                    if(s[j] != '#') continue;
                    v[j] = min(v[j], dis);
                }

                dis = 0;
                for(int j = i - 1; j >= 0; j--){
                    dis++;
                    if(s[j] != '#') continue;
                    v[j] = min(v[j], dis);
                }
            }
        }

        /*
        for(int i = 0; i < n; i++) cout << v[i] << " ";
        cout << endl;
        */

        int ans = 0;
        int idx = 0;
        for(int i = 0; i < n; i++){
            if(s[i] != '#') continue;
            if(ans < v[i]){
                ans = v[i];
                idx = i;
            }
        }

        s[idx] = 'D';

        return;
    }

}

signed main(){
    
    while(1){
        int n, q; cin >> n >> q;
        if(n == 0 && q == 0) break;
        
        string seet;
        for(int i = 0; i < n; i++) seet = seet + "#";
        
        for(int i = 0; i < q; i++){
            char op; cin >> op;
            f(seet, op);
        }

        cout << seet << endl;
        
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n,m;
char t[120];

void A(char a){
  int i=1;
  while(t[i]!=0) i++;
  t[i]=a;
}

void B(){
  for(int i=n;i>=1;i--){
    if(t[i]==0){
      t[i]='B';
      break;
    }
  }
}

void C(int cnt){
  if(cnt==0) {
    if(n%2==0) t[n/2+1]='C';
    else t[(n+1)/2]='C';
    return;
  }


  for(int i=1;i<=n;i++){
    if(t[i]!=0&&t[i+1]==0) {
      t[i+1]='C';
      break;
    }
    if(t[i]!=0&&t[i-1]==0){
      t[i-1]='C';
      break;
    }
  }
}

void D(int cnt){
  if(cnt==0){
    t[1]='D';
    return;
  }
  int mx=0,idx=0,c=0;
  for(int i=1;i<=n;i++) {
    if(t[i]==0) c++;
    else c=0;
    if(mx+mx%2<c)mx=c,idx=i;
  }

  if(mx<=2&&t[n]==0&&t[n-1]==0) {
    t[n]='D';
    return;
  }  

  if(mx<=2){
    A('D');
    return ;
  }

  if(idx==n) t[n]='D';
  else   t[(idx-(idx-mx+1))/2+(idx-mx+1)]='D';
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    memset(t,0,sizeof(t));
    t[0]=t[n+1]=1;
    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(i);
    }

    for(int i=1;i<=n;i++)if(t[i]==0)t[i]='#';
    t[n+1]=0;
    printf("%s\n",t+1);
  }
  return 0;
}