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 // 次の人を読み込む
			}
		}
		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Println(chair[i])
			} else {
				fmt.Printf("%s ", chair[i])
			}
		}
	}
}

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 <cstring>
#include <algorithm>

using namespace std;

int chair[100],pos,n,m;

int d(char c){
	if(c == 'A'){
		for(int i=0;i<n;i++){
			if(chair[i] == -1) return i;
		}
	}else if(c == 'B'){
		for(int i=n-1;i>=0;i--){
			if(chair[i] == -1){
				if(i == 0){
					if(chair[i+1] != 'A') return i;
				}else if(i == n-1){
					if(chair[i-1] != 'A') return i;
				}else{
					if(chair[i-1] != 'A' && chair[i+1] != 'A') return i;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(chair[i] == -1) return i;
		}
	}else if(c == 'C'){
		for(int i=0;i<n;i++){
			if(chair[i] != -1){
				if(i+1 < n && chair[i+1] == -1) return i+1;
				if(0 <= i-1 && chair[i-1] == -1) return i-1;
			}
		}
		return n/2+1;
	}else{
		int d_min_max = 0,d_pos=-1,tmp;
		for(int i=0;i<n;i++){
			//ó¢Ä¢éÖqÆÅàß¢lÌ£ðßé
			
			if(chair[i] == -1){
				int dist_min = 1 << 28;
				if(i != n-1){
					tmp = 1;
					while(i+tmp < n && chair[i+tmp] == -1) tmp++;
					if(i+tmp<n){
						dist_min = min(dist_min, tmp);
					}
				}
				if(i != 0){
					tmp = 1;
					while(i-tmp >= 0 && chair[i-tmp] == -1) tmp++;
					if(i-tmp >= 0){
						dist_min = min(dist_min, tmp);
					}
				}
				if(d_min_max < dist_min && dist_min != 1 << 28){
					d_min_max = dist_min;
					d_pos = i;
				}
			}
		}
		if(d_pos != -1) return d_pos;
		for(int i=0;i<n;i++){
			if(chair[i] == -1) return i;
		}
	}
}

int main(){
	while(cin >> n >> m){
		if(!(n|m)) break;
		char c;
		memset(chair, -1, sizeof(chair));
		for(int i=0;i<m;i++){
			cin >> c;
			chair[d(c)] = c;
		}
		for(int i=0;i<n;i++){
			if(chair[i] == -1){
				cout << "#";
			}else{
				cout << (char)chair[i];
			}
		}
		cout << endl;
	}
}

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

char ch[1000];
int n,m;

int putA(char x){
	for(int i = 1 ; i <= n ; i++){
		if( ch[i] == '#' ){
			ch[i] = x;
			break;
		}
	}
	return 0;
}
int putB(char x){
	for(int i = n ; i >= 1 ; i--){
		if(ch[i-1] != 'A' && ch[i+1] != 'A' ){
			ch[i] = x;
			return 0;
		}
	}
	// else
	putA(x);
}

int putC(char x){
	
	for(int i = 1 ; i <= n ; i++){
		if( ch[i] != '#'){
			if( i+1 <= n && ch[i+1] == '#' ){ ch[i+1] = x; return 0; }
			if( i-1 >= 1 && ch[i-1] == '#' ){ ch[i-1] = x; return 0; }
		}
	}
	if( n % 2 ){
		ch[(n+1)/2] = x;
	}else{
		ch[n/2+1] = x;
	}
}
int putD(char x){
	int distance = 0 , idx = 0;
	for(int i = 1 ; i <= n ; i++){
		int best = 10000;
		for(int j = 1 ; j <= n ; j++){
			if( ch[j] != '#' ) best = min(abs(i-j),best);
		}
		if( best > distance ){
			idx = i;
			distance = best;
		}
	}
	ch[idx] = x;
}
int main(){
	while(cin >> n >> m && n){
		for(int i = 0 ; i < 1000 ; i++) ch[i] = '#';
		for(int i = 0 ; i < m ; i++){
			char c;
			cin >> c;
			if( c == 'A' ) putA(c);
			if( c == 'B' ) putB(c);
			if( c == 'C' ) putC(c);
			if( c == 'D' ) putD(c);

		}
			for(int i = 1 ; i <= n ; i++)
				cout << ch[i];
			cout << endl;


	}
}

C++: #include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int main() {
	int n, m, temp;
	char str, str2[101], str3[101] = { 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';
							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;
					for (int j = 0; j < n; j++) {
						if (str3[j] == '#')/*goto end*/;
						if (j == n - 1)str3[temp] = 'C';
					}
				}
				temp = 0;
			}
			else if (str2[i] == 'D') {
				temp = 0;
				int gun = 0, x, y;
				for (int j = 0; j < n; j++) {
					int  q = 0, w = 0;
					if (str3[j] == '#') {
						x = y = j;
						while (1) {
							x++;
							y--;
							if (x <= n || y > 0) {
								if (str3[x] == '#' &&x <= n) {
									q++;
									if (gun < q && gun>0) {
										str3[x] = 'D';
										str3[gun] = '#';
										gun = q;
										temp++;
									}
								}
								if (str3[y] == '#' &&y > 0) {
									w++;
									if (gun < w&& gun>0) {
										str3[y] = 'D';
										str3[gun] = '#';
										gun = w;
										temp++;
									}
								}
							}
							else {
								goto loop;
							}
						}
					}
				}
			loop:
				if (temp == 0) {
					for (int j = 0; j < n; j++) {
						if (str3[j] == '#') {
							str3[j] = 'D';
							goto end;
						}
						if (j == n - 1) {
							str3[0] = 'D';
						}
					}
				}
				temp = 0;
			}
		end:;
			/*for (int i = 0; i < n; i++) {
				cout << str3[i];
			}
			cout << endl;*/
		}
		for (int i = 0; i < n; i++) {
			cout << str3[i];
		}
		cout << endl;
		memset(str3, 0, sizeof(str3));
		memset(str2, 0, sizeof(str2));
		temp = 0;
	}
}