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
		}
		chairs := make([]string, n)
		for i := range chairs {
			chairs[i] = "#"
		}
		sit := func(who string) {
			if who == "A" {
				chairs[getStringIndex(chairs, "#")] = "A" // A国の人は左から見て行って空いている席を見つけ次第座る
				// log.Println(chairs)
			} else if who == "B" {
				f := true
				for i := n-1; i > -1; i-- {
					// B国の人はA国人の隣以外で、右端から空いている椅子に座る
					if chairs[i] == "#" && (i == 0 || chairs[i-1] != "A") && (i == n-1 || chairs[i+1] != "A") {
								chairs[i] = "B"
								f = false
								break
					}
				}
				// A国人の隣しか空いていない場合、我慢して左端から空いている椅子に座る
				if f {
					chairs[getStringIndex(chairs, "#")] = "B"
				}
				// log.Println(chairs)
			} else if who == "C" { // C国人は人の隣に座りたい
				for i := 0; i < n; i++ {
					if chairs[i] != "#" {
						if i + 1 <= n-1 && chairs[i+1] == "#" {
							chairs[i+1] = "C"
							break
						} else if i - 1 >= 0 && chairs[i-1] == "#" {
							chairs[i-1] = "C"
							break
						}
					}
				}
				// log.Println(chairs)
			} else { // who == "D"
				// D国の人は人から離れて座りたい
				// どうしても誰かの隣に座らなければならない場合、その中で一番左側にある椅子に座る
				scores := make([]int, n)
				for i := range scores {
					scores[i] = INF
				}
				for i, v := range chairs {
					if v == "#" {
						scores[i]++
					}
				}
				for i := n-1; i > -1; i-- {
					tmp := 0
					if chairs[i] == "#" {
						tmp++
					} else {
						tmp = 0
					}
					scores[i] = min(scores[i], tmp)
				}
				chairs[getIntIndex(scores, getMax(scores))] = "D"
				// log.Println(chairs)
			}
		}
		scanner.Scan()
		if first := scanner.Text(); first == "A" || first == "D" {
			chairs[0] = first
		} else if first == "B" {
			chairs[len(chairs)-1] = "B"
		} else {
			chairs[n/2] = "C"
		}
		// log.Println(chairs)
		for i := 0; i < m-1; i++ {
			scanner.Scan()
			sit(scanner.Text())
		}
		fmt.Println(strings.Join(chairs, ""))
	}
}

func getStringIndex(chairs []string, who string) int {
	for i, v := range chairs {
		if v == who {
			return i
		}
	}
	return -1
}

func getIntIndex(scores []int, target int) int {
	for i, v := range scores {
		if v == target {
			return i
		}
	}
	return -1
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func getMax(scores []int) int {
	tmp := -1
	for _, v := range scores {
		if tmp < v {
			tmp = v
		}
	}
	return tmp
}

C++: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void solve1(string& s, char c) {
	s[s.find('#')] = c;
}
void solve2(string& s) {
	for (int i = s.size() - 1; i >= 0; i--) {
		if ((i < s.size() - 1 && s[i + 1] != 'A') && (i > 0 && s[i - 1] != 'A')) {
			s[i] = 'B'; return;
		}
	}
	solve1(s, 'B');
}
vector<int> dist(string& s) {
	vector<int> ret(s.size(), 999999999);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '#') {
			for (int j = 0; j < s.size(); j++) {
				ret[j] = min(ret[j], abs(i - j));
			}
		}
	}
	return ret;
}
void solve3(string &s) {
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '#') {
			if (i < s.size() - 1 && s[i + 1] == '#') {
				s[i + 1] = 'C'; return;
			}
			if (i > 0 && s[i - 1] == '#') {
				s[i - 1] = 'C'; return;
			}
		}
	}
	if (s.size() % 2 == 1) s[(s.size() - 1) / 2] = 'C';
	else s[s.size() / 2] = 'C';
}
void solve4(string &s) {
	vector<int> ret = dist(s);
	s[max_element(ret.begin(), ret.end()) - ret.begin()] = 'D';
}
int N, Q;
int main() {
	while (cin >> N >> Q, N) {
		string s(N, '#'), t;
		while (Q--) {
			cin >> t;
			if (t == "A") solve1(s, 'A');
			if (t == "B") solve2(s);
			if (t == "C") solve3(s);
			if (t == "D") solve4(s);
		}
		cout << s << endl;
	}
	return 0;
}

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

void seatA(string& seats)
{
  for (string::iterator it(seats.begin()); it != seats.end(); ++it) {
    if (*it == '#') {
      *it = 'A';
      return;
    }
  }
}

void seatB(string& seats)
{
  string::reverse_iterator fallback = seats.rend();
  for (string::reverse_iterator it(seats.rbegin()); it != seats.rend(); ++it) {
    if (*it == '#') {
      // right
      if ((it == seats.rbegin() || *(it-1) != 'A')
          && (it+1 != seats.rend() || *(it+1) != 'A')) {
        *it = 'B';
        return;
      }
      fallback = it;
    }
  }
  *fallback = 'B';
}

void seatC(string& seats)
{
  for (string::iterator it(seats.begin()); it != seats.end(); ++it) {
    if (*it != '#') {
      if (it != seats.end() && *(it+1) == '#') {
        *(it+1) = 'C';
        return;
      }
      if (it != seats.begin() && *(it-1) == '#') {
        *(it-1) = 'C';
      }
    }
  }
  seats[seats.size()/2] = 'C';
}

void seatD(string& seats)
{
  vector<int> tbl(seats.size(), 1000);
  for (string::size_type i = 0; i < seats.size(); i++) {
    if (seats[i] != '#') {
      for (vector<int>::size_type j = 0; j < tbl.size(); j++) {
        tbl[j] = min(tbl[j], abs(static_cast<int>(i - j)));
      }
    }
  }
  if (tbl.front() == 1000) {
    seats[0] = 'D';
  } else {
    string::size_type pos = 0;
    int m = -1;
    for (string::size_type i = 0; i < seats.size(); i++) {
      if (tbl[i] > m) {
        m = tbl[i];
        pos = i;
      }
    }
    seats[pos] = 'D';
  }
}

int main()
{
  int n, m;
  while (cin >> n >> m && n != 0) {
    string seats(n, '#');
    for (int i = 0; i < m; i++) {
      string s;
      cin >> s;
      if (s == "A") {
        seatA(seats);
      } else if (s == "B") {
        seatB(seats);
      } else if (s == "C") {
        seatC(seats);
      } else {
        seatD(seats);
      }
    }
    cout << seats << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main()
{
	int n,m,i,j,k;
	char c;
	while(scanf("%d%d",&n,&m),n)
	{
		int a[100]={0};	//0:emptyツ、{1,2,3,4}={A,B,C,D}
		for(k=0;k<m;++k)
		{
			scanf(" %c",&c);
			if(c=='A')
			{
				for(i=0;i<n;++i)if(!a[i]){a[i]=1;break;}
			}
			if(c=='B')
			{
				for(i=n-1;i>=0;--i)if(!a[i]){a[i]=2;break;}
			}
			if(c=='C')
			{
				if(!k)a[n/2]=3;
				else
				{
					for(i=0;i<n;++i)
					{
						if(i!=n-1&&a[i]&&!a[i+1]){a[i+1]=3;break;}
						if(i&&a[i]&&!a[i-1]){a[i-1]=3;break;}
					}
				}
			}
			if(c=='D')
			{
				if(!k)a[0]=4;
				else
				{
					int mc=-1,mi=-1;
					int cc=999;
					for(i=0;i<n;++i)
					{
						for(j=i;j>=0;--j)if(a[j]){if(cc>i-j)cc=i-j;break;}
						for(j=i;j<n;++j)if(a[j]){if(cc<j-i)cc=j-i;break;}
						if(mc<cc)mc=cc,mi=i;
					}
					a[mi]=4;
				}
			}
		}
		for(i=0;i<n;++i)putchar("#ABCD"[a[i]]);
		puts("");
	}
	return 0;
}

C++: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void solve2(string& s) {
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == '#' && (i == s.size() - 1 || s[i + 1] != 'A') && (i == 0 || s[i - 1] != 'A')) {
			s[i] = 'B'; return;
		}
	}
	s[s.find('#')] = 'B';
}
void solve3(string &s) {
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '#') {
			if (i < s.size() - 1 && s[i + 1] == '#') {
				s[i + 1] = 'C'; return;
			}
			if (i > 0 && s[i - 1] == '#') {
				s[i - 1] = 'C'; return;
			}
		}
	}
	s[s.size() / 2] = 'C';
}
void solve4(string &s) {
	vector<int> ret(s.size(), 999999999);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '#') {
			for (int j = 0; j < s.size(); j++) {
				ret[j] = min(ret[j], abs(i - j));
			}
		}
	}
	s[max_element(ret.begin(), ret.end()) - ret.begin()] = 'D';
}
int N, Q;
int main() {
	while (cin >> N >> Q, N) {
		string s(N, '#'), t;
		while (Q--) {
			cin >> t;
			if (t == "A") s[s.find('#')] = 'A';
			if (t == "B") solve2(s);
			if (t == "C") solve3(s);
			if (t == "D") solve4(s);
		}
		cout << s << endl;
	}
	return 0;
}