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>
using namespace std;
int x[1001], n, m; char c;
void _a() {
	for (int i = 1; i <= n; i++) {
		if (x[i] == 0) { x[i] = 1; return; }
	}
}
void _b() {
	for (int i = n; i >= 1; i--) {
		if (x[i] == 0 && x[i - 1] != 1 && x[i + 1] != 1) {
			x[i] = 2; return;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (x[i] == 0) { x[i] = 2; return; }
	}
}
void _c() {
	for (int i = 1; i <= n; i++) {
		if (x[i] >= 1) {
			if (x[i + 1] == 0 && i < n) { x[i + 1] = 3; return; }
			if (x[i - 1] == 0 && i >= 2) { x[i - 1] = 3; return; }
		}
	}
	if (n % 2 == 0) { x[(n / 2) + 1] = 3; }
	else { x[(n + 1) / 2] = 3; }
}
void _d(int p) {
	int dist[1000];
	for (int i = 0; i < 1000; i++) { dist[i] = 10000000; }
	if (p == 0) { x[1] = 4; return; }
	for (int i = 1; i <= n; i++) {
		if (x[i] == 0) { continue; }
		for (int j = 1; j <= n; j++) {
			int D = i - j;
			if (D < 0) { D = -D; }
			dist[j] = min(dist[j], D);
		}
	}
	int maxn = 0, maxid = 0;
	for (int i = 1; i <= n; i++) {
		if (maxn < dist[i]) { maxn = dist[i]; maxid = i; }
	}
	x[maxid] = 4;
}
int main() {
	while (true) {
		cin >> n >> m; if (n == 0 && m == 0) { break; }
		for (int i = 1; i <= 1000; i++) { x[i] = 0; }
		for (int i = 0; i < m; i++) {
			cin >> c;
			int d = c - 'A' + 1;
			if (d == 1) { _a(); }
			if (d == 2) { _b(); }
			if (d == 3) { _c(); }
			if (d == 4) { _d(i); }
		}
		for (int i = 1; i <= n; i++) {
			if (x[i] == 0) { cout << '#'; }
			if (x[i] == 1) { cout << 'A'; }
			if (x[i] == 2) { cout << 'B'; }
			if (x[i] == 3) { cout << 'C'; }
			if (x[i] == 4) { cout << 'D'; }
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define INF (1 << 29)
int main(){
  char chair[105];
  int n, m;
  char c;
  while(cin >> n >> m, n){
    fill(chair, chair + n, '#');
    chair[n] = 0;
    for(int i = 0;i < m;i++){
      cin >> c;
      switch(c){
      case 'A':
      left :
	for(int j = 0;j < n;j++){
	  if(chair[j] == '#'){
	    chair[j] = c;
	    break;
	  }
	}
	break;
      case 'B':
	for(int j = n - 1;j >= 0;j++){
	  if((j == 0 || chair[j - 1] != 'A') && chair[j] == '#' && chair[j + 1] != 'A'){
	    chair[j] = c;
	    break;
	  }
	  if(j == 0)goto left;
	}
	break;
      case 'C':
	for(int j = 0;j < n;j++){
	  if(j != '#'){
	    if(chair[j + 1] == '#'){
	      chair[j + 1] = c;
	      break;
	    }
	    if(j != 0 && chair[j - 1] == '#'){
	      chair[j - 1] = c;
	      break;
	    }
	  }
	  if(j == n - 1){
	    chair[n / 2] = c;
	  }
	}
	break;
      case 'D':
	int p = 0, s = -1;
	for(int j = 0;j < n;j++){
	  if(chair[j] != '#')continue;
	  int t = INF;
	  for(int k = j;k < n;k++){
	    if(chair[k] != '#'){
	      t = k - j;
	    }
	  }
	  for(int k = j;k >= 0;k--){
	    if(chair[k] != '#'){
	      t = min(t, j - k);
	    }
	  }
	  if(t > s){
	    p = j;
	    s = t;
	  }
	}
	if(p == INF){
	  chair[n - 1] = c;
	}
	else{
	  chair[p] = c;
	}
	break;
      }
    }
    printf("%s\n", chair);
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

char s[200], a[2];
int main() {
	bool b;
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		memset(s, 0, sizeof(s)); rep(i, n)s[i] = '#';
		rep(i, m) {
			scanf("%s", a);
			switch (a[0]) {
			case 'A':
				rep(i, n) { if (s[i] == '#') { s[i] = 'A'; break; } }
				break;
			case 'B':
				b = false;
				for (int i = n - 1; i >= 0; i--) {
					if (s[i] == '#' && (!i || s[i - 1] != 'A') && (i + 1 >= n || s[i + 1] != 'A')) {
						b = true; s[i] = 'B'; break;
					}
				}
				if (!b)rep(i, n) { if (s[i] == '#') { s[i] = 'B'; break; } }
				break;
			case 'C':
				b = false;
				rep(i, n) {
					if (s[i] != '#') {
						if (i + 1 < n&&s[i + 1] == '#') { s[i + 1] = 'C'; b = true; break; }
						if (i&&s[i - 1] == '#') { s[i - 1] == 'C'; b = true; break; }
					}
				}
				if (!b)s[n & 1 ? (n + 1) / 2 : n / 2 + 1] = 'C';
				break;
			case 'D':
				int k, Max = 0;
				rep(i, n) {
					if (s[i] != '#')continue;
					int cnt = INT_MAX;
					int t = i - 1;
					for (; t >= 0 && s[t] == '#'; t--);
					if (t == -1)t = INT_MAX;
					cnt = t;
					t = i + 1;
					for (; t < n&&s[t] == '#'; t++);
					if (t == n)t = INT_MAX;
					cnt = min(cnt, t);
					if (Max < cnt) {
						k = i; Max = cnt;
					}
				}
				s[k] = 'D';
				break;
			}
		}
		printf("%s\n", s);
	}
}