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<iostream>
using namespace std;

int main(){

  int n,m;
  int j;
  char chair[100];
  char p;
  int left,max,m_left;

  while(1){

    cin >> n >> m;
    if(n==0 && m==0)
      break;

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


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

    cin >> p;

    if(p=='A'){
      j=0;
      while(chair[j]!='#')
	j++;

      chair[j]='A';
    }///////////////////////A

    else if(p=='B'){
      j=n-1;
      while(1){
	if(chair[j]=='#'){
	  if(j==n-1 && chair[j-1]!='A')
	    break;

	  else if(j>0 && chair[j+1]!='A' && chair[j-1]!='A')
	    break;

	  else if(chair[j+1]!='A')
	    break;
	  
	  else if(j==0){
	    j=-1;
	    break;
	  }
	}
	j--;
      }

      if(j!=-1)
	chair[j]='B';

      else{
	j=0;
	while(chair[j]!='#')
	  j++;

	chair[j]='B';
      }

    }////////////////////////B


    else if(p=='C'){
      j=0;
      while(1){
	if(chair[j]!='#'){
	  if(chair[j+1]=='#'&&j!=n-1){
	    j++;
	    break;
	  }
	  else if(j!=0 && chair[j-1]=='#'){
	    j--;
	    break;
	  }
	}

	if(j==n-1){
	  j=-1;
	  break;
	}

	j++;
      }

      if(j==-1){
	if(n%2==1)
	  j=(n+1)/2;
	else
	  j=n/2+1;
      }

      chair[j] = 'C';
    }///////////////////////C


    else{
      left=0; max=1; m_left=0;
      j=1;
      while(j<=n-1){
	if(chair[j]!='#'){
	  left=j;

	  j++;
	}

	if(max < j-left){
	  max = j-left;
	  m_left = left;
	}

	j++;
      }

      if(max <= 2){
	j=0;
	while(j<n && chair[j] != '#')
	  j++;
      }

      else if(max == n-1)
	j=0;

      else{
	if(max%2==1)
	  j=m_left+max/2 +1;
	else
	  j=m_left+max/2;
      }


      chair[j]='D';

    }///////////////////////D

    }


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


    cout << endl;

  }


  return 0;

}

C++: #include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int main() {
	int n, m, temp;
	char str, str2[10001], str3[10001] = { NULL };
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0)return 0;
		for (int i = 0; i < m; i++) {
			cin >> str2[i];
		}
		for (int i = 0; i < n; i++) {
			str3[i] = '#';
		}
		for (int i = 0; i < m; i++) {
			if (str2[i] == 'A') {
				for (int j = 0; j < n; j++) {
					if (str3[j] == '#') {
						str3[j] = 'A';
						goto end;
					}
				}
			}
			else if (str2[i] == 'B') {
				for (int j = n - 1; j > 0; j--) {
					if (str3[j] == '#'&&str3[j - 1] != 'A'&&str3[j + 1] != 'A') {
						str3[j] = 'B';
						temp++;
						goto end;
					}
				}
				if (temp == 0) {
					for (int j = 0; j < n; j++) {
						if (str3[j] == '#') {
							str3[j] = 'B';
							temp++;
							goto end;
						}
					}
				}
				/*if (temp == 0) {
					for (int j = 0; j < n; j++) {
						if (str3[j] == '#') {
							str3[j] = 'B';
							goto end;
						}
					}
				}*/
				temp = 0;
			}
			else if (str2[i] == 'C') {
				for (int j = 0; j < n; j++) {
					if (str3[j] != '#') {
						if (str3[j + 1] == '#') {
							str3[j + 1] = 'C';
							temp++;
							goto end;
						}
					}
				}
				if (temp == 0) {
					if (n % 2 == 0)temp = n / 2 + 1;
					else temp = (n + 1) / 2;
					str3[temp] = 'C';
				}
				temp = 0;
			}
			else if (str2[i] == 'D') {
				int q,p,d;
				int D[100];
				d = n * 2;
				for (p = 0; p < n;p++) {
					d++;
					if (str3[p] != '#')
						d = 0;
					D[p] = d;
				}
				for (d = n; p > 0;p--) {
					d++;
					if (str3[p] != '#')
						d = 0;
					if (d < D[p])
						D[p] = d;
				}
				for ( p = q = 0; q < n; q++)
					if (D[q] > D[p])
						p = q;
				str3[p] = 'D';
				goto end;
			}
			/*for (int i = 0; i < n; i++) {
				cout << str3[i];
			}
			cout << endl;*/
		end:;
		}
		for (int i = 0; i < n; i++) {
			cout << str3[i];
		}
		cout << endl;
		memset(str3, NULL, sizeof(str3));
		memset(str2, NULL, sizeof(str2));
		temp = 0;
	}
}

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

char chair[128];
int n, m;
const int M = 2;

void A() {
	for(int i = 0; i < n; i++) {
		if(chair[i+M] == 'N') {
			chair[i+M] = 'A';
			break;
		}
	}
}

void B() {
	for(int i = n-1; i >= 0; i--) {
		if(chair[i+M] == 'N' && chair[i+1+M] != 'A' && chair[i-1+M] != 'A') {
			chair[i+M] = 'B';
			return;
		}
	}
	for(int i = 0; i < n; i++) {
		if(chair[i+M] == 'N') {
			chair[i+M] = 'B';
			return;
		}
	}
}

void C() {
	for(int i = 0; i < n; i++) {
		/*
		if(chair[i+M] == 'N' && (chair[i-1+M] != 'N' || chair[i+1+M] != 'N')) {
			chair[i+M] = 'C';
			return;
		}
		*/
		if(chair[i+M] != 'N') {
			if(chair[i+1+M] == 'N' && i+1 < n) {
				chair[i+1+M] = 'C';
				return;
			}
			else if(chair[i-1+M] == 'N' && i-1 >= 0) {
				chair[i-1+M] = 'C';
				return;
			}
		}
	}
	chair[n/2+M] = 'C';
}

void D() {
	int mx = 0;
	int indx = 0;
	for(int i = 0; i < n; i++) {
		if(chair[i+M] == 'N') {
			int mn = 1000;
			for(int j = 0; j < n; j++) {
				if(chair[j+M] != 'N') {
					if(mn > abs(j - i))
						mn = abs(j - i);
				}
			}
			if(mn > mx) {
				mx = mn;
				indx = i;
			}
		}
	}
	chair[indx+M] = 'D';
}

int main() {
	while(cin >> n >> m, n || m) {
		for(int i = 0; i < 128; i++)
			chair[i] = 'N';
		for(int i = 0; i < m; i++) {
			string s;
			cin >> s;
			if(s[0] == 'A')
				A();
			else if(s[0] == 'B')
				B();
			else if(s[0] == 'C')
				C();
			else
				D();
		}
		for(int i = 0; i < n; i++) {
			cout << (chair[i+M] == 'N' ? '#' : chair[i+M]);
		}
		cout << endl;
	}
}