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>
#define MAX 100

using namespace std;

int n,m;
char chair[MAX+1];

void A(){
  for(int i = 0 ; i < n ; i++){

    if(chair[i] == '#'){
      chair[i] = 'A';
      return;
    }

  }
}

void B(){
  int pos = -1;

  for(int i = 0 ; i < n ; i++){
    if(chair[i] == 'A'){
      pos = i;
    }
  }

  if(pos == -1){
    for(int i = n-1 ; i >= 0 ; i--){

      if(chair[i] == '#'){
	chair[i] = 'B';
	return;
      }

    }

  }
  else{
    for(int i = n-1 ; i > 0 ; i--){

      if(chair[i] == '#' && chair[i-1] != 'A'){
	chair[i] = 'B';
	return;
      }
    }

    if(chair[0] == '#'){
      chair[0] = 'B';
      return;
    }

    for(int i = 0 ; i < n ; i++){

      if(chair[i] == '#'){
	chair[i] = 'B';
	return;
      }

    }
  }

}

void C(){
  int cnt = count(chair,chair+n,'#');

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

      if(chair[i] != '#' && chair[i+1] == '#'){
	chair[i+1] = 'C';
	return;
      }

    }
  }

}

void D(){
  int Breadth = 0,pos;

  for(int i = 0 ; i < n ; i++){
    int dist = (1<<29);
    for(int j = 0 ; j < n ; j++){
      if(chair[j] != '#'){
	dist = min(dist,abs(i-j));
      }
    }
    if(Breadth < dist){
      Breadth = dist;
      pos = i;
    } 
  }

  chair[pos] = 'D';
}

int main(){
  while(cin >> n >> m , n | m){
    char person;

    for(int i = 0 ; i < n ; i++)
      chair[i] = '#';

    for(int i = 0 ; i < m ; i++){
      cin >> person;
     
      switch(person){
      case 'A':	
	A(); 
	break;
      case 'B': 
	B(); 
	break;
      case 'C': 
	C(); 
	break;
      case 'D': 
	D(); 
	break;
      }

    }

    for(int i = 0 ; i < n ; i++){
      cout << chair[i];
    }
    cout << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef pair<int,int> P;
int chair[10001];
int n,m;
void A(){
	int ans=0;
	while(chair[ans]!=0)ans++;
	chair[ans]=1;
	return;
}
void B(){
	for(int i=n-1;i>=0;i--){
		if(chair[i]==0){
			if(i==0&&chair[1]!=1){chair[0]=2;return;}
			else if(i==n-1&&chair[n-2]!=1){chair[n-1]=2;return;}
			else if(0<i&&i<n-1&&chair[i-1]!=1&&chair[i+1]!=1){chair[i]=2;return;}
		}
	}
	int ans=0;
	while(chair[ans]!=0)ans++;
	chair[ans]=2;
	return;
}
void C(){
	int ans=0;
	if(chair[0]!=0){
		while(chair[ans]!=0)ans++;
		chair[ans]=3;
		return;
	}
	chair[n]=5;
	for(int i=0;i<n;i++){
		if(chair[i]!=0){
			if(chair[i+1]==0)chair[i+1]=3;
			else chair[i-1]=3;
			return;
		}
	}
	if(n%2)chair[(n+1)/2]=3;
	else chair[n/2+1]=3;
	return;
}
void D(){
	int a=0,f=0;
	P bl[5000];
	bool in=false;
	chair[n]=5;
	for(int i=0;i<=n;i++){
		if(in&&chair[i]!=0){
			in=false;bl[a++]=P(f,i);
		}else if(!in&&chair[i]==0){
			in=true;f=i;
		}
	}
	//for(int i=0;i<a;i++)printf("bl[%d]:[%d,%d)\n",i,bl[i].first,bl[i].second);
	if(bl[0].first==0&&bl[0].second==n){
		chair[0]=4;return;
	}else{
		int m,mlen=0;
		for(int i=0;i<a;i++){
			if(bl[i].second-bl[i].first>mlen){
				mlen=bl[i].second-bl[i].first;m=i;
			}
		}
		if(mlen%2){
			chair[bl[m].first+(mlen-1)/2]=4;return;
		}else{
			chair[bl[m].first+mlen/2-1]=4;return;
		}
	}
}
int main()
{
	while(cin>>n>>m&&(n||m)){
		fill(chair,chair+n,0);
		while(m--){
			char c;cin>>c;
			if(c=='A')A();
			if(c=='B')B();
			if(c=='C')C();
			if(c=='D')D();
		}
		for(int i=0;i<n;i++){
			if(chair[i]==0)cout<<'#';
			if(chair[i]==1)cout<<'A';
			if(chair[i]==2)cout<<'B';
			if(chair[i]==3)cout<<'C';
			if(chair[i]==4)cout<<'D';
		}
		cout<<endl;
	}
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int N, M;
int a[100];

void sit_from_left(int id) {
  for (int i = 0; i < N; ++i) {
    if (a[i] == -1) {
      a[i] = id;
      break;
    }
  }
}

void sit_a() {
  sit_from_left(0);
}

void sit_b() {
  bool sat = false;;
  for (int i = N - 1; i >= 0; --i) {
    if (a[i] != -1) {
      continue;
    }
    if (i > 0 && a[i - 1] == 0) {
      continue;
    }
    if (i < N - 1 && a[i + 1] == 0) {
      continue;
    }
    a[i] = 1;
    sat = true;
    break;
  }

  if (sat) {
    return;
  }

  sit_from_left(1);
}

void sit_c() {
  bool sat = false;
  for (int i = 0; i < N; ++i) {
    if (a[i] == -1) {
      continue;
    }
    if (i < N - 1 && a[i + 1] == -1) {
      a[i + 1] = 2;
      sat = true;
      break;
    }
    if (i > 0 && a[i - 1] == -1) {
      a[i - 1] = 2;
      sat = true;
      break;
    }
  }

  if (sat) {
    return;
  }

  a[N / 2] = 2;
}

void sit_d() {
  int m = 0;
  int mi = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i] != -1) {
      continue;
    }
    int l = N;
    int r = N;
    for (int j = i; j >= 0; --j) {
      if (a[j] != -1) {
        l = i - j;
        break;
      }
    }
    for (int j = i; j < N; ++j) {
      if (a[j] != -1) {
        r = j - i;
        break;
      }
    }
    if (m < min(l, r)) {
      m = min(l, r);
      mi = i;
    }
  }
  a[mi] = 3;
}

void print_seat() {
  for (int i = 0; i < N; ++i) {
    if (a[i] < 0) {
      cout << (char)'#';
    } else {
      cout << (char)('A' + a[i]);
    }
  }
  cout << endl;
}

int main() {
  while (1) {
    cin >> N >> M;
    if (!N && !M) {
      break;
    }
    fill(a, a + N, -1);
    for (int i = 0; i < M; ++i) {
      string s;
      cin >> s;
      if (s == "A") {
        sit_a();
      } else if (s == "B") {
        sit_b();
      } else if (s == "C") {
        sit_c();
      } else if (s == "D") {
        sit_d();
      }
    }
    print_seat();
  }
  return 0;
}