So, you have a sequence of objects, that you need to be stacked. You've given us no information about the restraints you must operate under when this is done. In other words, there is not nearly enough information to provide you with a reasonable response.
Your problem may fall under the purview of a bin packing algorithm. You may want to google that and see if it can be of use to you.
This doesn't seem to have anything to do with C++.
you can stack another pack on top of the other one if there are only one type and the one after is greater alpha..ACMICPC has only one A, and when you check through, can't find another A, so the compiler moves to the the next box which is C, it checks if C >A if so it stacks it on top of A, Then moves to M, Yes M is < C but it can not stack it on top of C for there are other C's on the data(container) that has not been processed, so it creates another stack.
on the other hand if it was,
ACMICPCA then this would have 4 stack because C can not be stack on top of A since there is an A data that is not been processed
does this make sense.. it is a bit hard to explain on here
Also... as a side effect of explaining the process to me,... you also have explained exactly what you need to do to accomplish this in a program. You laid out the step-by-step logic in your post... now all you need to do it take each of those steps and write the code for it.
So in explaining this... maybe you have answered your own question?