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++: //08
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    string c(n,'#');
    for(int i=0;i<m;i++){
      char p;
      cin>>p;
      switch(p){
      case 'B':
	int j;
	for(j=c.size()-1;j>=0;j--){
	  if(c[j]=='#'&&(j==0||c[j-1]!='A')&&(j==c.size()-1||c[j+1]!='A')){
	    c[j]=p;
	    break;
	  }
	}
	if(j>=0)break;
      case 'A':
	for(int j=0;j<c.size();j++){
	  if(c[j]=='#'){
	    c[j]=p;
	    break;
	  }
	}
	break;
      case 'C':
	if(i==0){
	  c[n/2]=p;
	}else{
	  for(int j=0;j<c.size();j++){
	    if(c[j]!='#'){
	      if(j!=c.size()-1&&c[j+1]=='#'){
		c[j+1]=p;
		break;
	      }else if(j!=0&&c[j-1]=='#'){
		c[j-1]=p;
		break;
	      }
	    }
	  }
	}
	break;
      case 'D':
	if(i==0){
	  c[0]=p;
	}else{
	  int b;
	  int d=-1;
	  for(int j=0;j<c.size();j++){
	    if(c[j]=='#'){
	      int cd;
	      int l;
	      for(l=j;l>=0&&c[l]=='#';l--);
	      cd=(l<0)?1000:j-l;
	      int r;
	      for(r=j;r<n&&c[r]=='#';r++);
	      cd=min(cd,(r==n)?1000:r-j);
	      if(d<cd){
		d=cd;
		b=j;
	      }
	    }
	  }
	  c[b]=p;
	}
	break;
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

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/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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

int main(){
	int n, m;
	while(cin>> n >> m && (n || m)){
		string chair(n, '#');
		char ch;
		rep(i, m){
			cin >> ch;
			if(ch == 'A'){
				rep(j, n){
					if(chair[j] == '#'){
						chair[j] = ch;
						break;
					}
				}
			}else if(ch == 'B'){
				bool ok = false;
				rep(j, n){
					if(chair[n-j-1] == '#' && 
						(j == 0 || chair[n-j] != 'A' 
						&& j == n - 1 || chair[n-j-2] != 'A')){
						chair[n-j-1] = ch;
						ok = true;
						break;
					}
				}
				if(!ok){
					rep(j, n){
						if(chair[j] == '#'){
							chair[j] = ch;
							break;
						}
					}
				}
			}else if(ch == 'C'){
				if(i == 0){
					chair[n/2] = ch;
				}else{
					rep(j, n){
						if(chair[j] != '#'){
							if(chair[j+1] == '#'){
								chair[j+1] = ch;
								break;
							}else if(j > 0 && chair[j-1] == '#'){
								chair[j-1] = ch;
								break;
							}
						}
					}
				}
			}else{
				if(i == 0){
					chair[0] = ch;
				}else{
					int best = 0;
					int dis = 0;
					rep(i, n){
						if(chair[i] != '#') continue;
						int d = INF;
						rep(j, n){
							if(chair[j] != '#'){
								d = min(abs(j - i), d);
							}
						}
						if(d > dis){
							dis = d;
							best = i;
						}
					}
					chair[best] = ch;
				}
			}
		}
		cout << chair << endl;
	}
	return 0;
}