#include <stdio.h>
char stack[100];
int top = -1;
void push(char x) {
stack[++top] = x;
}
void pop() {
top--;
}
int main() {
char input[] = {'A','A','B','A','B','B'};
int n = sizeof(input) / sizeof(input[0]);
for (int i = 0; i < n; i++) {
push(input[i]);
if (top >= 1 && stack[top-1] == 'A' && stack[top] == 'B') {
pop();
pop();
}
}
for (int j = 0; j <= top; j++) {
printf("%c ", stack[j]);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: